durable-db 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -272,6 +272,7 @@ const generate = typeof _generate === "function" ? _generate : _generate.default
272
272
  * is the identity function.
273
273
  */
274
274
  const DEV_EPOCH_IMPORT = "virtual:durable-db/__devEpoch";
275
+ const ARKTYPE_LOCAL = "__ddType";
275
276
  function parseProgram(code) {
276
277
  return parse(code, {
277
278
  sourceType: "module",
@@ -286,8 +287,17 @@ function parseExpression(code) {
286
287
  if (t.isExpressionStatement(stmt)) return stmt.expression;
287
288
  throw new Error(`Expected expression, got ${stmt?.type ?? "unknown"}`);
288
289
  }
290
+ function asImportName(n) {
291
+ return typeof n === "string" ? {
292
+ imported: n,
293
+ local: n
294
+ } : n;
295
+ }
289
296
  function createNamedImport(names, source) {
290
- const specifiers = names.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name)));
297
+ const specifiers = names.map((n) => {
298
+ const { imported, local } = asImportName(n);
299
+ return t.importSpecifier(t.identifier(local), t.identifier(imported));
300
+ });
291
301
  return t.importDeclaration(specifiers, t.stringLiteral(source));
292
302
  }
293
303
  function ensureNamedImports(body, source, names) {
@@ -299,7 +309,10 @@ function ensureNamedImports(body, source, names) {
299
309
  return;
300
310
  }
301
311
  const have = new Set(existing.specifiers.filter((sp) => t.isImportSpecifier(sp)).map((sp) => sp.imported.name));
302
- for (const n of names) if (!have.has(n)) existing.specifiers.push(t.importSpecifier(t.identifier(n), t.identifier(n)));
312
+ for (const n of names) {
313
+ const { imported, local } = asImportName(n);
314
+ if (!have.has(imported)) existing.specifiers.push(t.importSpecifier(t.identifier(local), t.identifier(imported)));
315
+ }
303
316
  }
304
317
  function buildMigrationsObject(migrations) {
305
318
  if (!migrations || migrations.size === 0) return t.objectExpression([]);
@@ -571,7 +584,7 @@ function buildStubBodyStatements(config) {
571
584
  const bindingExpr = t.memberExpression(t.identifier("env"), t.identifier(database.bindingName));
572
585
  const instanceKeyExpr = buildInstanceKeyExpr(database);
573
586
  const commonStatements = [
574
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier("argsSchema"), t.callExpression(t.identifier("type"), [parseExpression(action.argsSchemaSource)]))]),
587
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier("argsSchema"), t.callExpression(t.identifier(ARKTYPE_LOCAL), [parseExpression(action.argsSchemaSource)]))]),
575
588
  t.variableDeclaration("const", [t.variableDeclarator(t.identifier("validatedArgs"), t.callExpression(t.memberExpression(t.identifier("argsSchema"), t.identifier("assert")), [t.identifier("args")]))]),
576
589
  ...buildDoShortPath(config),
577
590
  t.variableDeclaration("const", [t.variableDeclarator(t.identifier("instanceKey"), instanceKeyExpr)]),
@@ -603,7 +616,10 @@ function applyActionTransforms(body, ctx) {
603
616
  "registerAction",
604
617
  "getDoContext",
605
618
  "callAction",
606
- "type"
619
+ {
620
+ imported: "type",
621
+ local: ARKTYPE_LOCAL
622
+ }
607
623
  ]);
608
624
  ensureNamedImports(body, DEV_EPOCH_IMPORT, ["applyDevEpoch"]);
609
625
  if (database.transport === "websocket") ensureNamedImports(body, "durable-db/transport/websocket", ["WebSocketTransport"]);
@@ -626,7 +642,7 @@ function applyActionTransforms(body, ctx) {
626
642
  const action = actionsInFile.find((a) => a.exportName === exportName);
627
643
  const validatorId = t.identifier(`__validator_${exportName}`);
628
644
  const handlerId = t.identifier(`__handler_${exportName}`);
629
- replaced.push(t.variableDeclaration("const", [t.variableDeclarator(validatorId, t.callExpression(t.identifier("type"), [parseExpression(action.argsSchemaSource)]))]));
645
+ replaced.push(t.variableDeclaration("const", [t.variableDeclarator(validatorId, t.callExpression(t.identifier(ARKTYPE_LOCAL), [parseExpression(action.argsSchemaSource)]))]));
630
646
  replaced.push(t.variableDeclaration("const", [t.variableDeclarator(handlerId, parseExpression(action.handlerSource))]));
631
647
  replaced.push(t.expressionStatement(t.callExpression(t.identifier("registerAction"), [
632
648
  t.stringLiteral(dbName),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "durable-db",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eagerpatch/durable-db.git"