Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package: Analytics Engine #399

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6319887
first up
CraigglesO Oct 1, 2022
e6351c5
remove TODOs; adjust readmes
CraigglesO Oct 1, 2022
6eac0a4
migrate to execute sql data inside engine code
CraigglesO Oct 1, 2022
3ae1bfd
parse INTERVAL; add test cases
CraigglesO Oct 2, 2022
da11a07
interval, complete test cases
CraigglesO Oct 2, 2022
b307341
add miniflare api access + tests; drop 'UNIQUE'
CraigglesO Oct 2, 2022
a5d2fee
fix options; all analytics exists inside singular db now
CraigglesO Oct 2, 2022
cc1547d
add jest testings
CraigglesO Oct 2, 2022
5fb6b54
add jest testings
CraigglesO Oct 2, 2022
b2810df
fix get->all; add http testing in minfilare; remove unique
CraigglesO Oct 2, 2022
11b2692
add vitest tests
CraigglesO Oct 2, 2022
13916f2
fix internal problem
CraigglesO Oct 2, 2022
d798479
TODATETIME fix
CraigglesO Oct 2, 2022
9b359ac
support QUANTILEWEIGHTED
CraigglesO Oct 3, 2022
39ed5cf
support QUANTILEWEIGHTED
CraigglesO Oct 3, 2022
7cb5d40
add formatting; minor fixes/adjustments
CraigglesO Oct 3, 2022
556d5eb
import sorting fix
CraigglesO Oct 3, 2022
16b28f0
more error cases
CraigglesO Oct 4, 2022
7abffeb
re-arrange
CraigglesO Oct 4, 2022
8e1e310
writeDataPoint is sync
CraigglesO Oct 4, 2022
44dc3d8
minor fixes
CraigglesO Oct 4, 2022
c25b639
ensure added functions & keywords are working
CraigglesO Oct 5, 2022
5865e9e
temporarily edit npx-import to get passing tests
CraigglesO Oct 6, 2022
62f63d5
pre-add better-sqlite
CraigglesO Oct 6, 2022
55b1d93
tmp move npx-import
CraigglesO Oct 6, 2022
ca5fe4f
ensure TODATETIME sticks to UTC
CraigglesO Oct 6, 2022
aabd9fb
update to latest master
CraigglesO Oct 24, 2022
c9b272d
first fix set
CraigglesO Oct 24, 2022
f93f54e
bug fixes
CraigglesO Oct 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add jest testings
  • Loading branch information
CraigglesO committed Oct 2, 2022
commit cc1547d34ef7b6da2c602fc7137ca5c477ef8405
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
async function get() {
// return fetch("http:https://localhost/cdn-cgi/mf/analytics_engine/sql", {
// method: "POST",
// body: "SELECT value FROM entries LIMIT 1;",
// }).then(async (b) => await b.json());
return queryMiniflareAnalyticsEngine(
"SELECT dataset, blob1, blob2, blob3, double1, double2, double3 FROM AE_TEST_DB LIMIT 1;"
);
}

test("AE test 1", async () => {
await AE_TEST_DB.writeDataPoint({
blobs: ["a", "b", "c"],
doubles: [0, 1, 2],
});
expect(await get()).toMatchObject({
dataset: "AE_TEST_DB",
blob1: "a",
blob2: "b",
blob3: "c",
double1: 0,
double2: 1,
double3: 2,
});
});
3 changes: 3 additions & 0 deletions packages/jest-environment-miniflare/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ test.serial(
"MiniflareEnvironment: runs Jest tests with Service Worker format workers",
async (t) => {
const [exitCode, output] = await runJest(".worker.spec.js", {
analyticsEngines: {
AE_TEST_DB: "AE_TEST_DB",
},
kvNamespaces: ["TEST_NAMESPACE"],
d1Databases: ["__D1_BETA__DB_1"],
sitePath: fixturesPath,
Expand Down
8 changes: 8 additions & 0 deletions packages/shared-test-environment/src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ declare global {
function flushMiniflareDurableObjectAlarms(
ids: DurableObjectId[]
): Promise<void>;
function queryMiniflareAnalyticsEngine(query: string): Promise<any>;
}

export interface MiniflareEnvironmentUtilities {
Expand All @@ -62,6 +63,7 @@ export interface MiniflareEnvironmentUtilities {
event: FetchEvent | ScheduledEvent | ExecutionContext
): Promise<WaitUntil>;
flushMiniflareDurableObjectAlarms(ids: DurableObjectId[]): Promise<void>;
queryMiniflareAnalyticsEngine(query: string): Promise<any>;
}

export async function createMiniflareEnvironmentUtilities(
Expand Down Expand Up @@ -106,5 +108,11 @@ export async function createMiniflareEnvironmentUtilities(
const factory = mf.getPluginStorage("DurableObjectsPlugin");
return plugin.flushAlarms(factory, ids);
},
async queryMiniflareAnalyticsEngine(query: string): Promise<any> {
CraigglesO marked this conversation as resolved.
Show resolved Hide resolved
const plugin = (await mf.getPlugins()).AnalyticsEnginePlugin;
const storage = mf.getPluginStorage("AnalyticsEnginePlugin");
const aeDB = await plugin.getStorage(storage);
return aeDB.prepare(query).get();
},
};
}