@instantdb/platform 0.22.95-experimental.surgical.20386874544.1 → 0.22.95

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.
@@ -1,35 +1,35 @@
1
1
 
2
- > @instantdb/platform@0.22.95-experimental.surgical.20386874544.1 build /home/runner/work/instant/instant/client/packages/platform
2
+ > @instantdb/platform@0.22.95 build /home/runner/work/instant/instant/client/packages/platform
3
3
  > rm -rf dist; npm run build:tshy && npm run build:standalone && npm run check-exports
4
4
 
5
5
  npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm.
6
6
  npm warn Unknown user config "always-auth". This will stop working in the next major version of npm.
7
7
 
8
- > @instantdb/platform@0.22.95-experimental.surgical.20386874544.1 build:tshy
8
+ > @instantdb/platform@0.22.95 build:tshy
9
9
  > tshy
10
10
 
11
11
  npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm.
12
12
  npm warn Unknown user config "always-auth". This will stop working in the next major version of npm.
13
13
 
14
- > @instantdb/platform@0.22.95-experimental.surgical.20386874544.1 build:standalone
14
+ > @instantdb/platform@0.22.95 build:standalone
15
15
  > vite build
16
16
 
17
17
  vite v5.4.14 building for production...
18
18
  transforming...
19
- ✓ 79 modules transformed.
19
+ ✓ 78 modules transformed.
20
20
  rendering chunks...
21
21
  computing gzip size...
22
- dist/standalone/index.umd.cjs 352.64 kB │ gzip: 95.88 kB
23
- dist/standalone/index.js 459.57 kB │ gzip: 107.83 kB
24
- ✓ built in 2.26s
22
+ dist/standalone/index.umd.cjs 350.68 kB │ gzip: 95.22 kB
23
+ dist/standalone/index.js 457.04 kB │ gzip: 107.08 kB
24
+ ✓ built in 2.16s
25
25
  npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm.
26
26
  npm warn Unknown user config "always-auth". This will stop working in the next major version of npm.
27
27
 
28
- > @instantdb/platform@0.22.95-experimental.surgical.20386874544.1 check-exports
28
+ > @instantdb/platform@0.22.95 check-exports
29
29
  > attw --pack .
30
30
 
31
31
 
32
- @instantdb/platform v0.22.95-experimental.surgical.20386874544.1
32
+ @instantdb/platform v0.22.95
33
33
 
34
34
  Build tools:
35
35
  - @arethetypeswrong/cli@^0.17.4
@@ -10,5 +10,4 @@ import { i, type InstantRules } from '@instantdb/core';
10
10
  import { exchangeCodeForToken, exchangeRefreshToken } from './serverOAuth.ts';
11
11
  export { type InstantAPIPlatformSchema, type InstantDBOAuthAccessToken, type OAuthHandlerConfig, type OAuthScope, type InstantRules, OAuthHandler, InstantOAuthError, generateSchemaTypescriptFile, validateSchema, SchemaValidationError, generatePermsTypescriptFile, apiSchemaToInstantSchemaDef, schemaTypescriptFileToInstantSchema, version, translatePlanSteps, PlatformApi, ProgressPromise, exchangeCodeForToken, exchangeRefreshToken, i, };
12
12
  export { diffSchemas, convertTxSteps, isRenamePromptItem, type RenameResolveFn, type MigrationTx, type MigrationTxSpecific, type MigrationTxTypes, type Identifier, } from './migrations.ts';
13
- export { formatKey, renderAttrCall, renderAttrProperty, renderEntityProperty, renderLinkValue, renderLinkProperty, renderLinksObject, } from './schemaCodegen.ts';
14
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,YAAY,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EACL,KAAK,wBAAwB,EAC7B,4BAA4B,EAC5B,cAAc,EACd,qBAAqB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,2BAA2B,EAC3B,WAAW,EACX,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mCAAmC,EAAE,MAAM,wBAAwB,C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AO,EACL,2BAA2B,EAC3B,WAAW,EACX,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mCAAmC,EAAE,MAAM,wBAAwB,CAAC;AAE7E,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,CAAC,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,YAAY,EACZ,iBAAiB,EACjB,4BAA4B,EAC5B,cAAc,EACd,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,EAC3B,mCAAmC,EACnC,OAAO,EACP,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,CAAC,GACF,CAAC;AAEF,OAAO,EACL,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,UAAU,GAChB,MAAM,iBAAiB,CAAC"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.renderLinksObject = exports.renderLinkProperty = exports.renderLinkValue = exports.renderEntityProperty = exports.renderAttrProperty = exports.renderAttrCall = exports.formatKey = exports.isRenamePromptItem = exports.convertTxSteps = exports.diffSchemas = exports.i = exports.exchangeRefreshToken = exports.exchangeCodeForToken = exports.ProgressPromise = exports.PlatformApi = exports.translatePlanSteps = exports.version = exports.schemaTypescriptFileToInstantSchema = exports.apiSchemaToInstantSchemaDef = exports.generatePermsTypescriptFile = exports.SchemaValidationError = exports.validateSchema = exports.generateSchemaTypescriptFile = exports.InstantOAuthError = exports.OAuthHandler = void 0;
6
+ exports.isRenamePromptItem = exports.convertTxSteps = exports.diffSchemas = exports.i = exports.exchangeRefreshToken = exports.exchangeCodeForToken = exports.ProgressPromise = exports.PlatformApi = exports.translatePlanSteps = exports.version = exports.schemaTypescriptFileToInstantSchema = exports.apiSchemaToInstantSchemaDef = exports.generatePermsTypescriptFile = exports.SchemaValidationError = exports.validateSchema = exports.generateSchemaTypescriptFile = exports.InstantOAuthError = exports.OAuthHandler = void 0;
7
7
  const oauthCommon_ts_1 = require("./oauthCommon.js");
8
8
  Object.defineProperty(exports, "InstantOAuthError", { enumerable: true, get: function () { return oauthCommon_ts_1.InstantOAuthError; } });
9
9
  const oauth_ts_1 = require("./oauth.js");
@@ -33,12 +33,4 @@ var migrations_ts_1 = require("./migrations.js");
33
33
  Object.defineProperty(exports, "diffSchemas", { enumerable: true, get: function () { return migrations_ts_1.diffSchemas; } });
34
34
  Object.defineProperty(exports, "convertTxSteps", { enumerable: true, get: function () { return migrations_ts_1.convertTxSteps; } });
35
35
  Object.defineProperty(exports, "isRenamePromptItem", { enumerable: true, get: function () { return migrations_ts_1.isRenamePromptItem; } });
36
- var schemaCodegen_ts_1 = require("./schemaCodegen.js");
37
- Object.defineProperty(exports, "formatKey", { enumerable: true, get: function () { return schemaCodegen_ts_1.formatKey; } });
38
- Object.defineProperty(exports, "renderAttrCall", { enumerable: true, get: function () { return schemaCodegen_ts_1.renderAttrCall; } });
39
- Object.defineProperty(exports, "renderAttrProperty", { enumerable: true, get: function () { return schemaCodegen_ts_1.renderAttrProperty; } });
40
- Object.defineProperty(exports, "renderEntityProperty", { enumerable: true, get: function () { return schemaCodegen_ts_1.renderEntityProperty; } });
41
- Object.defineProperty(exports, "renderLinkValue", { enumerable: true, get: function () { return schemaCodegen_ts_1.renderLinkValue; } });
42
- Object.defineProperty(exports, "renderLinkProperty", { enumerable: true, get: function () { return schemaCodegen_ts_1.renderLinkProperty; } });
43
- Object.defineProperty(exports, "renderLinksObject", { enumerable: true, get: function () { return schemaCodegen_ts_1.renderLinksObject; } });
44
36
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAsE;AAgCpE,kGAhCO,kCAAiB,OAgCP;AA/BnB,yCAIoB;AA0BlB,6FA3BA,uBAAY,OA2BA;AAzBd,yCAAyD;AA8BvD,4GA9BO,sCAA2B,OA8BP;AA7B7B,2CAKqB;AAqBnB,6GAxBA,wCAA4B,OAwBA;AAC5B,+FAxBA,0BAAc,OAwBA;AACd,sGAxBA,iCAAqB,OAwBA;AAtBvB,qCAIkB;AAoBhB,4GAvBA,oCAA2B,OAuBA;AAI3B,4FA1BA,oBAAW,OA0BA;AADX,mGAxBA,2BAAkB,OAwBA;AAtBpB,iEAA6E;AAoB3E,oHApBO,0DAAmC,OAoBP;AAlBrC,8DAAmC;AAmBjC,kBAnBK,oBAAO,CAmBL;AAlBT,6DAAuD;AAqBrD,gGArBO,oCAAe,OAqBP;AApBjB,0CAAuD;AAuBrD,kFAvBO,QAAC,OAuBP;AAtBH,qDAA8E;AAoB5E,qGApBO,qCAAoB,OAoBP;AACpB,qGArB6B,qCAAoB,OAqB7B;AAItB,iDASyB;AARvB,4GAAA,WAAW,OAAA;AACX,+GAAA,cAAc,OAAA;AACd,mHAAA,kBAAkB,OAAA;AAQpB,uDAQ4B;AAP1B,6GAAA,SAAS,OAAA;AACT,kHAAA,cAAc,OAAA;AACd,sHAAA,kBAAkB,OAAA;AAClB,wHAAA,oBAAoB,OAAA;AACpB,mHAAA,eAAe,OAAA;AACf,sHAAA,kBAAkB,OAAA;AAClB,qHAAA,iBAAiB,OAAA","sourcesContent":["import { InstantOAuthError, type OAuthScope } from './oauthCommon.ts';\nimport {\n type InstantDBOAuthAccessToken,\n type OAuthHandlerConfig,\n OAuthHandler,\n} from './oauth.ts';\nimport { generatePermsTypescriptFile } from './perms.ts';\nimport {\n type InstantAPIPlatformSchema,\n generateSchemaTypescriptFile,\n validateSchema,\n SchemaValidationError,\n} from './schema.ts';\nimport {\n apiSchemaToInstantSchemaDef,\n PlatformApi,\n translatePlanSteps,\n} from './api.ts';\nimport { schemaTypescriptFileToInstantSchema } from './typescript-schema.ts';\n\nimport version from './version.ts';\nimport { ProgressPromise } from './ProgressPromise.ts';\nimport { i, type InstantRules } from '@instantdb/core';\nimport { exchangeCodeForToken, exchangeRefreshToken } from './serverOAuth.ts';\n\nexport {\n type InstantAPIPlatformSchema,\n type InstantDBOAuthAccessToken,\n type OAuthHandlerConfig,\n type OAuthScope,\n type InstantRules,\n OAuthHandler,\n InstantOAuthError,\n generateSchemaTypescriptFile,\n validateSchema,\n SchemaValidationError,\n generatePermsTypescriptFile,\n apiSchemaToInstantSchemaDef,\n schemaTypescriptFileToInstantSchema,\n version,\n translatePlanSteps,\n PlatformApi,\n ProgressPromise,\n exchangeCodeForToken,\n exchangeRefreshToken,\n i,\n};\n\nexport {\n diffSchemas,\n convertTxSteps,\n isRenamePromptItem,\n type RenameResolveFn,\n type MigrationTx,\n type MigrationTxSpecific,\n type MigrationTxTypes,\n type Identifier,\n} from './migrations.ts';\n\nexport {\n formatKey,\n renderAttrCall,\n renderAttrProperty,\n renderEntityProperty,\n renderLinkValue,\n renderLinkProperty,\n renderLinksObject,\n} from './schemaCodegen.ts';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAsE;AAgCpE,kGAhCO,kCAAiB,OAgCP;AA/BnB,yCAIoB;AA0BlB,6FA3BA,uBAAY,OA2BA;AAzBd,yCAAyD;AA8BvD,4GA9BO,sCAA2B,OA8BP;AA7B7B,2CAKqB;AAqBnB,6GAxBA,wCAA4B,OAwBA;AAC5B,+FAxBA,0BAAc,OAwBA;AACd,sGAxBA,iCAAqB,OAwBA;AAtBvB,qCAIkB;AAoBhB,4GAvBA,oCAA2B,OAuBA;AAI3B,4FA1BA,oBAAW,OA0BA;AADX,mGAxBA,2BAAkB,OAwBA;AAtBpB,iEAA6E;AAoB3E,oHApBO,0DAAmC,OAoBP;AAlBrC,8DAAmC;AAmBjC,kBAnBK,oBAAO,CAmBL;AAlBT,6DAAuD;AAqBrD,gGArBO,oCAAe,OAqBP;AApBjB,0CAAuD;AAuBrD,kFAvBO,QAAC,OAuBP;AAtBH,qDAA8E;AAoB5E,qGApBO,qCAAoB,OAoBP;AACpB,qGArB6B,qCAAoB,OAqB7B;AAItB,iDASyB;AARvB,4GAAA,WAAW,OAAA;AACX,+GAAA,cAAc,OAAA;AACd,mHAAA,kBAAkB,OAAA","sourcesContent":["import { InstantOAuthError, type OAuthScope } from './oauthCommon.ts';\nimport {\n type InstantDBOAuthAccessToken,\n type OAuthHandlerConfig,\n OAuthHandler,\n} from './oauth.ts';\nimport { generatePermsTypescriptFile } from './perms.ts';\nimport {\n type InstantAPIPlatformSchema,\n generateSchemaTypescriptFile,\n validateSchema,\n SchemaValidationError,\n} from './schema.ts';\nimport {\n apiSchemaToInstantSchemaDef,\n PlatformApi,\n translatePlanSteps,\n} from './api.ts';\nimport { schemaTypescriptFileToInstantSchema } from './typescript-schema.ts';\n\nimport version from './version.ts';\nimport { ProgressPromise } from './ProgressPromise.ts';\nimport { i, type InstantRules } from '@instantdb/core';\nimport { exchangeCodeForToken, exchangeRefreshToken } from './serverOAuth.ts';\n\nexport {\n type InstantAPIPlatformSchema,\n type InstantDBOAuthAccessToken,\n type OAuthHandlerConfig,\n type OAuthScope,\n type InstantRules,\n OAuthHandler,\n InstantOAuthError,\n generateSchemaTypescriptFile,\n validateSchema,\n SchemaValidationError,\n generatePermsTypescriptFile,\n apiSchemaToInstantSchemaDef,\n schemaTypescriptFileToInstantSchema,\n version,\n translatePlanSteps,\n PlatformApi,\n ProgressPromise,\n exchangeCodeForToken,\n exchangeRefreshToken,\n i,\n};\n\nexport {\n diffSchemas,\n convertTxSteps,\n isRenamePromptItem,\n type RenameResolveFn,\n type MigrationTx,\n type MigrationTxSpecific,\n type MigrationTxTypes,\n type Identifier,\n} from './migrations.ts';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,aAAa,EACb,wBAAwB,EACxB,cAAc,EAIf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAIL,gBAAgB,EACjB,MAAM,WAAW,CAAC;AAOnB,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,UAAU,CAAC;IACjB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,aAAa,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,aAAa,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,OAAO,CAAC;IACd,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,cAAc,CAAC;IACrB,mBAAmB,EAAE,M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AO,EAAE,MAAM;CAI5B;AAED,eAAO,MAAM,cAAc,GACzB,QAAQ,gBAAgB,EACxB,yBAAyB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,SA8DrD,CAAC"}
@@ -12,12 +12,18 @@ exports.attrFwdName = attrFwdName;
12
12
  exports.attrRevName = attrRevName;
13
13
  exports.generateSchemaTypescriptFile = generateSchemaTypescriptFile;
14
14
  const util_ts_1 = require("./util.js");
15
- const schemaCodegen_ts_1 = require("./schemaCodegen.js");
15
+ function attrDefToCodeString([name, attr]) {
16
+ var _a;
17
+ const type = ((_a = attr.metadata.derivedType) === null || _a === void 0 ? void 0 : _a.type) || attr.valueType || 'any';
18
+ const unique = attr.config.unique ? '.unique()' : '';
19
+ const index = attr.config.indexed ? '.indexed()' : '';
20
+ const required = attr.required ? '' : '.optional()';
21
+ return `${(0, util_ts_1.formatKey)(name)}: i.${type}()${unique}${index}${required}`;
22
+ }
16
23
  function entityDefToCodeStr(name, edef) {
17
- return (0, schemaCodegen_ts_1.renderEntityProperty)(name, edef.attrs, {
18
- keyOptions: { alwaysQuote: true, quote: '"' },
19
- trailingComma: true,
20
- });
24
+ const attrBlock = (0, util_ts_1.joinWithTrailingSep)((0, util_ts_1.sortedEntries)(edef.attrs).map(attrDefToCodeString), ',\n', ',');
25
+ // a block of code for each entity
26
+ return `${(0, util_ts_1.formatKey)(name)}: i.entity({${attrBlock.length ? '\n' : ''}${(0, util_ts_1.indentLines)(attrBlock, 2)}${attrBlock.length ? '\n' : ''}})`;
21
27
  }
22
28
  function identEtype(ident) {
23
29
  return ident[1];
@@ -61,7 +67,7 @@ function roomDefToCodeStr(room) {
61
67
  ret += `\n${(0, util_ts_1.indentLines)(entityDefToCodeStr('presence', room.presence), 4)},`;
62
68
  }
63
69
  if (room.topics) {
64
- ret += `\n ${(0, schemaCodegen_ts_1.formatKey)('topics', { alwaysQuote: true, quote: '"' })}: {`;
70
+ ret += `\n "topics": {`;
65
71
  for (const [topicName, topicConfig] of Object.entries(room.topics)) {
66
72
  ret += `\n${(0, util_ts_1.indentLines)(entityDefToCodeStr(topicName, topicConfig), 6)},`;
67
73
  }
@@ -73,7 +79,7 @@ function roomDefToCodeStr(room) {
73
79
  function roomsCodeStr(rooms) {
74
80
  let ret = '{';
75
81
  for (const [roomType, roomDef] of Object.entries(rooms)) {
76
- ret += `\n ${(0, schemaCodegen_ts_1.formatKey)(roomType, { alwaysQuote: true, quote: '"' })}: ${roomDefToCodeStr(roomDef)},`;
82
+ ret += `\n ${(0, util_ts_1.formatKey)(roomType)}: ${roomDefToCodeStr(roomDef)},`;
77
83
  }
78
84
  ret += ret === '{' ? '}' : '\n}';
79
85
  return ret;
@@ -96,11 +102,7 @@ function generateSchemaTypescriptFile(prevSchema, newSchema, instantModuleName)
96
102
  // Take a look at this schema, and if everything looks good,
97
103
  // run \`push schema\` again to enforce the types.`
98
104
  : '';
99
- const linksEntriesCode = (0, schemaCodegen_ts_1.renderLinksObject)(newSchema.links, {
100
- keyOptions: { alwaysQuote: true, quote: '"' },
101
- stringQuote: '"',
102
- style: 'json',
103
- });
105
+ const linksEntriesCode = JSON.stringify(newSchema.links, null, 2).trim();
104
106
  // rooms
105
107
  const rooms = (prevSchema === null || prevSchema === void 0 ? void 0 : prevSchema.rooms) || {};
106
108
  const roomsCode = roomsCodeStr(rooms);
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":";;;AAsRA,gCAEC;AAED,gCAEC;AAED,8BAEC;AAED,oCAEC;AAED,oCAEC;AAED,oCAEC;AAED,oCAEC;AAED,kCAEC;AAED,kCAIC;AAsCD,oEAmEC;AAtZD,uCAKmB;AACnB,yDAI4B;AAiP5B,SAAS,kBAAkB,CACzB,IAAY,EACZ,IAIC;IAED,OAAO,IAAA,uCAAoB,EAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE;QAC5C,UAAU,EAAE,EAAE,WAAW,EAAE,IAA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CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,qBAAqB,CAC7B,GAAG,WAAW,qCAAqC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CACvE,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAhEW,QAAA,cAAc,kBAgEzB","sourcesContent":["import {\n AttrsDefs,\n CardinalityKind,\n DataAttrDef,\n EntityDef,\n InstantDBAttr,\n InstantDBCheckedDataType,\n InstantDBIdent,\n InstantSchemaDef,\n LinkAttrDef,\n RoomsDef,\n} from '@instantdb/core';\n\nimport {\n indentLines,\n joinWithTrailingSep,\n sortedEntries,\n GenericSchemaDef,\n} from './util.ts';\nimport {\n formatKey,\n renderEntityProperty,\n renderLinksObject,\n} from './schemaCodegen.ts';\n\nexport type InstantAPIPlatformSchema = {\n refs: Record<string, InstantDBAttr>;\n blobs: Record<string, Record<string, InstantDBAttr>>;\n};\n\nexport type InstantAPISchemaPlanAddAttrStep = {\n type: 'add-attr';\n friendlyDescription: string;\n attr: InstantDBAttr;\n};\n\nexport type InstantAPISchemaPlanDeleteAttrStep = {\n type: 'delete-attr';\n friendlyDescription: string;\n attrId: string;\n};\n\nexport type InstantAPISchemaPlanUpdateAttrStep = {\n type: 'update-attr';\n friendlyDescription: string;\n attr: InstantDBAttr;\n};\n\nexport type InstantAPISchemaPlanIndexStep = {\n type: 'index';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveIndexStep = {\n type: 'remove-index';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanUniqueStep = {\n type: 'unique';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveUniqueStep = {\n type: 'remove-unique';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRequiredStep = {\n type: 'required';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveRequiredStep = {\n type: 'remove-required';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanCheckDataTypeStep = {\n type: 'check-data-type';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n checkedDataType: InstantDBCheckedDataType;\n};\n\nexport type InstantAPISchemaPlanRemoveDataTypeStep = {\n type: 'remove-data-type';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\ntype InstantBackgroundSchemaBaseJob = {\n id: string;\n createdAt: Date;\n updatedAt: Date;\n status: 'completed' | 'waiting' | 'processing' | 'errored';\n workEstimate: number | null;\n workCompleted: number | null;\n error?:\n | 'invalid-triple-error'\n | 'invalid-attr-state-error'\n | 'triple-not-unique-error'\n | 'triple-too-large-error'\n | 'missing-required-error'\n | 'unexpected-error';\n invalidTriplesSample?: {\n entityId: string;\n value: any;\n jsonType:\n | 'string'\n | 'number'\n | 'boolean'\n | 'null'\n | 'object'\n | 'array'\n | 'date';\n }[];\n};\n\ntype InstantBackgroundSchemaBaseJobWithInvalidTriples =\n InstantBackgroundSchemaBaseJob & {\n invalidTriplesSample?: {\n entityId: string;\n value: any;\n jsonType:\n | 'string'\n | 'number'\n | 'boolean'\n | 'null'\n | 'object'\n | 'array'\n | 'date';\n }[];\n };\n\nexport interface InstantBackgroundSchemaRemoveDataTypeJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-data-type';\n}\n\nexport interface InstantBackgroundSchemaCheckDataTypeJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'check-data-type';\n checkedDataType: InstantDBCheckedDataType;\n}\n\nexport interface InstantBackgroundSchemaAddIndexJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'index';\n}\n\nexport interface InstantBackgroundSchemaRemoveIndexJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-index';\n}\n\nexport interface InstantBackgroundSchemaAddUniqueJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'unique';\n invalidUniqueValue?: any;\n}\n\nexport interface InstantBackgroundSchemaRemoveUniqueJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-unique';\n}\n\nexport interface InstantBackgroundSchemaAddRequiredJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'required';\n}\n\nexport interface InstantBackgroundSchemaRemoveRequiredJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-required';\n}\n\nexport type InstantAPISchemaPlanStep =\n | InstantAPISchemaPlanAddAttrStep\n | InstantAPISchemaPlanDeleteAttrStep\n | InstantAPISchemaPlanUpdateAttrStep\n | InstantAPISchemaPlanIndexStep\n | InstantAPISchemaPlanRemoveIndexStep\n | InstantAPISchemaPlanUniqueStep\n | InstantAPISchemaPlanRemoveUniqueStep\n | InstantAPISchemaPlanRequiredStep\n | InstantAPISchemaPlanRemoveRequiredStep\n | InstantAPISchemaPlanCheckDataTypeStep\n | InstantAPISchemaPlanRemoveDataTypeStep;\n\ntype BackgroundJobByStep = {\n index: InstantBackgroundSchemaAddIndexJob;\n 'remove-index': InstantBackgroundSchemaRemoveIndexJob;\n unique: InstantBackgroundSchemaAddUniqueJob;\n 'remove-unique': InstantBackgroundSchemaRemoveUniqueJob;\n required: InstantBackgroundSchemaAddRequiredJob;\n 'remove-required': InstantBackgroundSchemaRemoveRequiredJob;\n 'check-data-type': InstantBackgroundSchemaCheckDataTypeJob;\n 'remove-data-type': InstantBackgroundSchemaRemoveDataTypeJob;\n};\n\n// Adds the proper flavor of the backgroundJob type to the steps\n// that run in the background\nexport type WithBackgroundJob<P extends { type: string }> =\n P['type'] extends keyof BackgroundJobByStep\n ? P & { backgroundJob: BackgroundJobByStep[P['type']] }\n : P;\n\nexport type InstantAPISchemaPushAddAttrStep =\n WithBackgroundJob<InstantAPISchemaPlanAddAttrStep>;\n\nexport type InstantAPISchemaPushUpdateAttrStep =\n WithBackgroundJob<InstantAPISchemaPlanUpdateAttrStep>;\n\nexport type InstantAPISchemaPushIndexStep =\n WithBackgroundJob<InstantAPISchemaPlanIndexStep>;\n\nexport type InstantAPISchemaPushRemoveIndexStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveIndexStep>;\n\nexport type InstantAPISchemaPushUniqueStep =\n WithBackgroundJob<InstantAPISchemaPlanUniqueStep>;\n\nexport type InstantAPISchemaPushRemoveUniqueStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveUniqueStep>;\n\nexport type InstantAPISchemaPushRequiredStep =\n WithBackgroundJob<InstantAPISchemaPlanRequiredStep>;\n\nexport type InstantAPISchemaPushRemoveRequiredStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveRequiredStep>;\n\nexport type InstantAPISchemaPushCheckDataTypeStep =\n WithBackgroundJob<InstantAPISchemaPlanCheckDataTypeStep>;\n\nexport type InstantAPISchemaPushRemoveDataTypeStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveDataTypeStep>;\n\nexport type InstantAPISchemaPushStep =\n | InstantAPISchemaPushAddAttrStep\n | InstantAPISchemaPushUpdateAttrStep\n | InstantAPISchemaPushIndexStep\n | InstantAPISchemaPushRemoveIndexStep\n | InstantAPISchemaPushUniqueStep\n | InstantAPISchemaPushRemoveUniqueStep\n | InstantAPISchemaPushRequiredStep\n | InstantAPISchemaPushRemoveRequiredStep\n | InstantAPISchemaPushCheckDataTypeStep\n | InstantAPISchemaPushRemoveDataTypeStep;\n\nfunction entityDefToCodeStr(\n name: string,\n edef: EntityDef<\n AttrsDefs,\n Record<string, LinkAttrDef<CardinalityKind, string>>,\n any\n >,\n) {\n return renderEntityProperty(name, edef.attrs, {\n keyOptions: { alwaysQuote: true, quote: '\"' },\n trailingComma: true,\n });\n}\n\nexport function identEtype(ident: InstantDBIdent) {\n return ident[1];\n}\n\nexport function identLabel(ident: InstantDBIdent) {\n return ident[2];\n}\n\nexport function identName(ident: InstantDBIdent) {\n return `${identEtype(ident)}.${identLabel(ident)}`;\n}\n\nexport function attrFwdLabel(attr: InstantDBAttr) {\n return attr['forward-identity']?.[2];\n}\n\nexport function attrFwdEtype(attr: InstantDBAttr) {\n return attr['forward-identity']?.[1];\n}\n\nexport function attrRevLabel(attr: InstantDBAttr) {\n return attr['reverse-identity']?.[2];\n}\n\nexport function attrRevEtype(attr: InstantDBAttr) {\n return attr['reverse-identity']?.[1];\n}\n\nexport function attrFwdName(attr: InstantDBAttr) {\n return `${attrFwdEtype(attr)}.${attrFwdLabel(attr)}`;\n}\n\nexport function attrRevName(attr: InstantDBAttr) {\n if (attr['reverse-identity']) {\n return `${attrRevEtype(attr)}.${attrRevLabel(attr)}`;\n }\n}\n\nfunction easyPlural(strn: string, n: number) {\n return n === 1 ? strn : strn + 's';\n}\n\nfunction roomDefToCodeStr(room: RoomsDef[string]) {\n let ret = '{';\n\n if (room.presence) {\n ret += `\\n${indentLines(entityDefToCodeStr('presence', room.presence), 4)},`;\n }\n\n if (room.topics) {\n ret += `\\n ${formatKey('topics', { alwaysQuote: true, quote: '\"' })}: {`;\n\n for (const [topicName, topicConfig] of Object.entries(room.topics)) {\n ret += `\\n${indentLines(entityDefToCodeStr(topicName, topicConfig), 6)},`;\n }\n ret += `\\n }`;\n }\n\n ret += ret === '{' ? '}' : '\\n }';\n\n return ret;\n}\n\nfunction roomsCodeStr(rooms: RoomsDef) {\n let ret = '{';\n\n for (const [roomType, roomDef] of Object.entries(rooms)) {\n ret += `\\n ${formatKey(roomType, { alwaysQuote: true, quote: '\"' })}: ${roomDefToCodeStr(roomDef)},`;\n }\n ret += ret === '{' ? '}' : '\\n}';\n\n return ret;\n}\n\nexport function generateSchemaTypescriptFile(\n prevSchema: GenericSchemaDef | null | undefined,\n newSchema: GenericSchemaDef,\n instantModuleName: string,\n): string {\n // entities\n const entitiesEntriesCode = joinWithTrailingSep(\n sortedEntries(newSchema.entities).map(([etype, entityDef]) =>\n entityDefToCodeStr(etype, entityDef),\n ),\n ',\\n',\n ',',\n );\n\n const inferredAttrs: DataAttrDef<string, boolean, boolean>[] = [];\n\n for (const entity of Object.values(newSchema.entities)) {\n for (const attr of Object.values(entity.attrs)) {\n if ((attr.metadata.derivedType as any)?.origin === 'inferred') {\n inferredAttrs.push(attr);\n }\n }\n }\n\n const entitiesObjCode = `{\\n${indentLines(entitiesEntriesCode, 2)}\\n}`;\n\n const entitiesComment =\n inferredAttrs.length > 0\n ? `// We inferred ${inferredAttrs.length} ${easyPlural('attribute', inferredAttrs.length)}!\n// Take a look at this schema, and if everything looks good,\n// run \\`push schema\\` again to enforce the types.`\n : '';\n\n const linksEntriesCode = renderLinksObject(newSchema.links, {\n keyOptions: { alwaysQuote: true, quote: '\"' },\n stringQuote: '\"',\n style: 'json',\n });\n\n // rooms\n const rooms = prevSchema?.rooms || {};\n const roomsCode = roomsCodeStr(rooms);\n const kv = (k: string, v: string, comment?: string) => {\n const res = comment ? `${comment}\\n${k}: ${v}` : `${k}: ${v}`;\n return indentLines(res, 2);\n };\n\n const code = `// Docs: https://www.instantdb.com/docs/modeling-data\n\nimport { i } from \"${instantModuleName ?? '@instantdb/core'}\";\n\nconst _schema = i.schema({\n${kv('entities', entitiesObjCode, entitiesComment)},\n${kv('links', linksEntriesCode)},\n${kv('rooms', roomsCode)}\n});\n\n// This helps Typescript display nicer intellisense\ntype _AppSchema = typeof _schema;\ninterface AppSchema extends _AppSchema {}\nconst schema: AppSchema = _schema;\n\nexport type { AppSchema }\nexport default schema;\n`;\n\n return code;\n}\n\nexport class SchemaValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SchemaValidationError';\n }\n}\n\nexport const validateSchema = (\n schema: GenericSchemaDef,\n systemCatalogIdentNames: Record<string, Set<string>>,\n) => {\n const entityNames = Object.keys(schema.entities);\n\n for (const [etype, entityDef] of Object.entries(schema.entities)) {\n if (!etype.startsWith('$')) continue;\n if (!systemCatalogIdentNames[etype]) {\n throw new SchemaValidationError(\n 'The $ keyword is reserved for system namespaces.' +\n `\\nYou can't create '${etype}'. Perhaps call it '${etype.slice(1)}' instead?`,\n );\n }\n for (const [attrName, attrDef] of Object.entries(entityDef.attrs)) {\n if (systemCatalogIdentNames[etype].has(attrName)) {\n continue;\n }\n if (attrDef.required) {\n throw new SchemaValidationError(\n `The '${etype}' namespace is managed by the system and can't modify required constraints yet.` +\n `\\nMake sure to set ${etype}.${attrName} as optional.` +\n `\\n i.e { ${attrName}: i.${attrDef.valueType}().optional() }`,\n );\n }\n }\n }\n\n for (const link of Object.values(schema.links)) {\n if (\n systemCatalogIdentNames[link.forward.on] &&\n !systemCatalogIdentNames[link.forward.on].has(link.forward.label) &&\n link.forward.required\n ) {\n throw new SchemaValidationError(\n `The ${link.forward.on} namespace is managed by the system and can't modify required constraints yet.` +\n `\\nMake sure to set ${link.forward.on}${link.forward.label} as 'optional'.` +\n `\\n i.e { 'on': '${link.forward.on}', 'label': ${link.forward.label}, 'required': false }`,\n );\n }\n\n if (link.forward.has === 'many' && link.forward.onDelete === 'cascade') {\n throw new SchemaValidationError(\n `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: \"cascade\" with has: \"many\"`,\n );\n }\n if (link.reverse.has === 'many' && link.reverse.onDelete === 'cascade') {\n throw new SchemaValidationError(\n `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: \"cascade\" with has: \"many\"`,\n );\n }\n\n const linkDisplay = `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label}`;\n if (!entityNames.includes(link.forward.on)) {\n throw new SchemaValidationError(\n `${linkDisplay} connects to non existing entity \"${link.forward.on}\".`,\n );\n }\n if (!entityNames.includes(link.reverse.on)) {\n throw new SchemaValidationError(\n `${linkDisplay} connects to non existing entity \"${link.forward.on}\".`,\n );\n }\n }\n};\n"]}
1
+ {"version":3,"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DataAttrDef,\n EntityDef,\n InstantDBAttr,\n InstantDBCheckedDataType,\n InstantDBIdent,\n InstantSchemaDef,\n LinkAttrDef,\n RoomsDef,\n} from '@instantdb/core';\n\nimport {\n indentLines,\n joinWithTrailingSep,\n sortedEntries,\n formatKey,\n GenericSchemaDef,\n} from './util.ts';\n\nexport type InstantAPIPlatformSchema = {\n refs: Record<string, InstantDBAttr>;\n blobs: Record<string, Record<string, InstantDBAttr>>;\n};\n\nexport type InstantAPISchemaPlanAddAttrStep = {\n type: 'add-attr';\n friendlyDescription: string;\n attr: InstantDBAttr;\n};\n\nexport type InstantAPISchemaPlanDeleteAttrStep = {\n type: 'delete-attr';\n friendlyDescription: string;\n attrId: string;\n};\n\nexport type InstantAPISchemaPlanUpdateAttrStep = {\n type: 'update-attr';\n friendlyDescription: string;\n attr: InstantDBAttr;\n};\n\nexport type InstantAPISchemaPlanIndexStep = {\n type: 'index';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveIndexStep = {\n type: 'remove-index';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanUniqueStep = {\n type: 'unique';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveUniqueStep = {\n type: 'remove-unique';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRequiredStep = {\n type: 'required';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveRequiredStep = {\n type: 'remove-required';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanCheckDataTypeStep = {\n type: 'check-data-type';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n checkedDataType: InstantDBCheckedDataType;\n};\n\nexport type InstantAPISchemaPlanRemoveDataTypeStep = {\n type: 'remove-data-type';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\ntype InstantBackgroundSchemaBaseJob = {\n id: string;\n createdAt: Date;\n updatedAt: Date;\n status: 'completed' | 'waiting' | 'processing' | 'errored';\n workEstimate: number | null;\n workCompleted: number | null;\n error?:\n | 'invalid-triple-error'\n | 'invalid-attr-state-error'\n | 'triple-not-unique-error'\n | 'triple-too-large-error'\n | 'missing-required-error'\n | 'unexpected-error';\n invalidTriplesSample?: {\n entityId: string;\n value: any;\n jsonType:\n | 'string'\n | 'number'\n | 'boolean'\n | 'null'\n | 'object'\n | 'array'\n | 'date';\n }[];\n};\n\ntype InstantBackgroundSchemaBaseJobWithInvalidTriples =\n InstantBackgroundSchemaBaseJob & {\n invalidTriplesSample?: {\n entityId: string;\n value: any;\n jsonType:\n | 'string'\n | 'number'\n | 'boolean'\n | 'null'\n | 'object'\n | 'array'\n | 'date';\n }[];\n };\n\nexport interface InstantBackgroundSchemaRemoveDataTypeJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-data-type';\n}\n\nexport interface InstantBackgroundSchemaCheckDataTypeJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'check-data-type';\n checkedDataType: InstantDBCheckedDataType;\n}\n\nexport interface InstantBackgroundSchemaAddIndexJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'index';\n}\n\nexport interface InstantBackgroundSchemaRemoveIndexJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-index';\n}\n\nexport interface InstantBackgroundSchemaAddUniqueJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'unique';\n invalidUniqueValue?: any;\n}\n\nexport interface InstantBackgroundSchemaRemoveUniqueJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-unique';\n}\n\nexport interface InstantBackgroundSchemaAddRequiredJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'required';\n}\n\nexport interface InstantBackgroundSchemaRemoveRequiredJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-required';\n}\n\nexport type InstantAPISchemaPlanStep =\n | InstantAPISchemaPlanAddAttrStep\n | InstantAPISchemaPlanDeleteAttrStep\n | InstantAPISchemaPlanUpdateAttrStep\n | InstantAPISchemaPlanIndexStep\n | InstantAPISchemaPlanRemoveIndexStep\n | InstantAPISchemaPlanUniqueStep\n | InstantAPISchemaPlanRemoveUniqueStep\n | InstantAPISchemaPlanRequiredStep\n | InstantAPISchemaPlanRemoveRequiredStep\n | InstantAPISchemaPlanCheckDataTypeStep\n | InstantAPISchemaPlanRemoveDataTypeStep;\n\ntype BackgroundJobByStep = {\n index: InstantBackgroundSchemaAddIndexJob;\n 'remove-index': InstantBackgroundSchemaRemoveIndexJob;\n unique: InstantBackgroundSchemaAddUniqueJob;\n 'remove-unique': InstantBackgroundSchemaRemoveUniqueJob;\n required: InstantBackgroundSchemaAddRequiredJob;\n 'remove-required': InstantBackgroundSchemaRemoveRequiredJob;\n 'check-data-type': InstantBackgroundSchemaCheckDataTypeJob;\n 'remove-data-type': InstantBackgroundSchemaRemoveDataTypeJob;\n};\n\n// Adds the proper flavor of the backgroundJob type to the steps\n// that run in the background\nexport type WithBackgroundJob<P extends { type: string }> =\n P['type'] extends keyof BackgroundJobByStep\n ? P & { backgroundJob: BackgroundJobByStep[P['type']] }\n : P;\n\nexport type InstantAPISchemaPushAddAttrStep =\n WithBackgroundJob<InstantAPISchemaPlanAddAttrStep>;\n\nexport type InstantAPISchemaPushUpdateAttrStep =\n WithBackgroundJob<InstantAPISchemaPlanUpdateAttrStep>;\n\nexport type InstantAPISchemaPushIndexStep =\n WithBackgroundJob<InstantAPISchemaPlanIndexStep>;\n\nexport type InstantAPISchemaPushRemoveIndexStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveIndexStep>;\n\nexport type InstantAPISchemaPushUniqueStep =\n WithBackgroundJob<InstantAPISchemaPlanUniqueStep>;\n\nexport type InstantAPISchemaPushRemoveUniqueStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveUniqueStep>;\n\nexport type InstantAPISchemaPushRequiredStep =\n WithBackgroundJob<InstantAPISchemaPlanRequiredStep>;\n\nexport type InstantAPISchemaPushRemoveRequiredStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveRequiredStep>;\n\nexport type InstantAPISchemaPushCheckDataTypeStep =\n WithBackgroundJob<InstantAPISchemaPlanCheckDataTypeStep>;\n\nexport type InstantAPISchemaPushRemoveDataTypeStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveDataTypeStep>;\n\nexport type InstantAPISchemaPushStep =\n | InstantAPISchemaPushAddAttrStep\n | InstantAPISchemaPushUpdateAttrStep\n | InstantAPISchemaPushIndexStep\n | InstantAPISchemaPushRemoveIndexStep\n | InstantAPISchemaPushUniqueStep\n | InstantAPISchemaPushRemoveUniqueStep\n | InstantAPISchemaPushRequiredStep\n | InstantAPISchemaPushRemoveRequiredStep\n | InstantAPISchemaPushCheckDataTypeStep\n | InstantAPISchemaPushRemoveDataTypeStep;\n\nfunction attrDefToCodeString([name, attr]: [\n string,\n DataAttrDef<string, boolean, boolean>,\n]) {\n const type =\n (attr.metadata.derivedType as any)?.type || attr.valueType || 'any';\n const unique = attr.config.unique ? '.unique()' : '';\n const index = attr.config.indexed ? '.indexed()' : '';\n const required = attr.required ? '' : '.optional()';\n return `${formatKey(name)}: i.${type}()${unique}${index}${required}`;\n}\n\nfunction entityDefToCodeStr(\n name: string,\n edef: EntityDef<\n AttrsDefs,\n Record<string, LinkAttrDef<CardinalityKind, string>>,\n any\n >,\n) {\n const attrBlock = joinWithTrailingSep(\n sortedEntries(edef.attrs).map(attrDefToCodeString),\n ',\\n',\n ',',\n );\n\n // a block of code for each entity\n return `${formatKey(name)}: i.entity({${attrBlock.length ? '\\n' : ''}${indentLines(attrBlock, 2)}${attrBlock.length ? '\\n' : ''}})`;\n}\n\nexport function identEtype(ident: InstantDBIdent) {\n return ident[1];\n}\n\nexport function identLabel(ident: InstantDBIdent) {\n return ident[2];\n}\n\nexport function identName(ident: InstantDBIdent) {\n return `${identEtype(ident)}.${identLabel(ident)}`;\n}\n\nexport function attrFwdLabel(attr: InstantDBAttr) {\n return attr['forward-identity']?.[2];\n}\n\nexport function attrFwdEtype(attr: InstantDBAttr) {\n return attr['forward-identity']?.[1];\n}\n\nexport function attrRevLabel(attr: InstantDBAttr) {\n return attr['reverse-identity']?.[2];\n}\n\nexport function attrRevEtype(attr: InstantDBAttr) {\n return attr['reverse-identity']?.[1];\n}\n\nexport function attrFwdName(attr: InstantDBAttr) {\n return `${attrFwdEtype(attr)}.${attrFwdLabel(attr)}`;\n}\n\nexport function attrRevName(attr: InstantDBAttr) {\n if (attr['reverse-identity']) {\n return `${attrRevEtype(attr)}.${attrRevLabel(attr)}`;\n }\n}\n\nfunction easyPlural(strn: string, n: number) {\n return n === 1 ? strn : strn + 's';\n}\n\nfunction roomDefToCodeStr(room: RoomsDef[string]) {\n let ret = '{';\n\n if (room.presence) {\n ret += `\\n${indentLines(entityDefToCodeStr('presence', room.presence), 4)},`;\n }\n\n if (room.topics) {\n ret += `\\n \"topics\": {`;\n\n for (const [topicName, topicConfig] of Object.entries(room.topics)) {\n ret += `\\n${indentLines(entityDefToCodeStr(topicName, topicConfig), 6)},`;\n }\n ret += `\\n }`;\n }\n\n ret += ret === '{' ? '}' : '\\n }';\n\n return ret;\n}\n\nfunction roomsCodeStr(rooms: RoomsDef) {\n let ret = '{';\n\n for (const [roomType, roomDef] of Object.entries(rooms)) {\n ret += `\\n ${formatKey(roomType)}: ${roomDefToCodeStr(roomDef)},`;\n }\n ret += ret === '{' ? '}' : '\\n}';\n\n return ret;\n}\n\nexport function generateSchemaTypescriptFile(\n prevSchema: GenericSchemaDef | null | undefined,\n newSchema: GenericSchemaDef,\n instantModuleName: string,\n): string {\n // entities\n const entitiesEntriesCode = joinWithTrailingSep(\n sortedEntries(newSchema.entities).map(([etype, entityDef]) =>\n entityDefToCodeStr(etype, entityDef),\n ),\n ',\\n',\n ',',\n );\n\n const inferredAttrs: DataAttrDef<string, boolean, boolean>[] = [];\n\n for (const entity of Object.values(newSchema.entities)) {\n for (const attr of Object.values(entity.attrs)) {\n if ((attr.metadata.derivedType as any)?.origin === 'inferred') {\n inferredAttrs.push(attr);\n }\n }\n }\n\n const entitiesObjCode = `{\\n${indentLines(entitiesEntriesCode, 2)}\\n}`;\n\n const entitiesComment =\n inferredAttrs.length > 0\n ? `// We inferred ${inferredAttrs.length} ${easyPlural('attribute', inferredAttrs.length)}!\n// Take a look at this schema, and if everything looks good,\n// run \\`push schema\\` again to enforce the types.`\n : '';\n\n const linksEntriesCode = JSON.stringify(newSchema.links, null, 2).trim();\n\n // rooms\n const rooms = prevSchema?.rooms || {};\n const roomsCode = roomsCodeStr(rooms);\n const kv = (k: string, v: string, comment?: string) => {\n const res = comment ? `${comment}\\n${k}: ${v}` : `${k}: ${v}`;\n return indentLines(res, 2);\n };\n\n const code = `// Docs: https://www.instantdb.com/docs/modeling-data\n\nimport { i } from \"${instantModuleName ?? '@instantdb/core'}\";\n\nconst _schema = i.schema({\n${kv('entities', entitiesObjCode, entitiesComment)},\n${kv('links', linksEntriesCode)},\n${kv('rooms', roomsCode)}\n});\n\n// This helps Typescript display nicer intellisense\ntype _AppSchema = typeof _schema;\ninterface AppSchema extends _AppSchema {}\nconst schema: AppSchema = _schema;\n\nexport type { AppSchema }\nexport default schema;\n`;\n\n return code;\n}\n\nexport class SchemaValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SchemaValidationError';\n }\n}\n\nexport const validateSchema = (\n schema: GenericSchemaDef,\n systemCatalogIdentNames: Record<string, Set<string>>,\n) => {\n const entityNames = Object.keys(schema.entities);\n\n for (const [etype, entityDef] of Object.entries(schema.entities)) {\n if (!etype.startsWith('$')) continue;\n if (!systemCatalogIdentNames[etype]) {\n throw new SchemaValidationError(\n 'The $ keyword is reserved for system namespaces.' +\n `\\nYou can't create '${etype}'. Perhaps call it '${etype.slice(1)}' instead?`,\n );\n }\n for (const [attrName, attrDef] of Object.entries(entityDef.attrs)) {\n if (systemCatalogIdentNames[etype].has(attrName)) {\n continue;\n }\n if (attrDef.required) {\n throw new SchemaValidationError(\n `The '${etype}' namespace is managed by the system and can't modify required constraints yet.` +\n `\\nMake sure to set ${etype}.${attrName} as optional.` +\n `\\n i.e { ${attrName}: i.${attrDef.valueType}().optional() }`,\n );\n }\n }\n }\n\n for (const link of Object.values(schema.links)) {\n if (\n systemCatalogIdentNames[link.forward.on] &&\n !systemCatalogIdentNames[link.forward.on].has(link.forward.label) &&\n link.forward.required\n ) {\n throw new SchemaValidationError(\n `The ${link.forward.on} namespace is managed by the system and can't modify required constraints yet.` +\n `\\nMake sure to set ${link.forward.on}${link.forward.label} as 'optional'.` +\n `\\n i.e { 'on': '${link.forward.on}', 'label': ${link.forward.label}, 'required': false }`,\n );\n }\n\n if (link.forward.has === 'many' && link.forward.onDelete === 'cascade') {\n throw new SchemaValidationError(\n `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: \"cascade\" with has: \"many\"`,\n );\n }\n if (link.reverse.has === 'many' && link.reverse.onDelete === 'cascade') {\n throw new SchemaValidationError(\n `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: \"cascade\" with has: \"many\"`,\n );\n }\n\n const linkDisplay = `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label}`;\n if (!entityNames.includes(link.forward.on)) {\n throw new SchemaValidationError(\n `${linkDisplay} connects to non existing entity \"${link.forward.on}\".`,\n );\n }\n if (!entityNames.includes(link.reverse.on)) {\n throw new SchemaValidationError(\n `${linkDisplay} connects to non existing entity \"${link.forward.on}\".`,\n );\n }\n }\n};\n"]}
@@ -10,5 +10,4 @@ import { i, type InstantRules } from '@instantdb/core';
10
10
  import { exchangeCodeForToken, exchangeRefreshToken } from './serverOAuth.ts';
11
11
  export { type InstantAPIPlatformSchema, type InstantDBOAuthAccessToken, type OAuthHandlerConfig, type OAuthScope, type InstantRules, OAuthHandler, InstantOAuthError, generateSchemaTypescriptFile, validateSchema, SchemaValidationError, generatePermsTypescriptFile, apiSchemaToInstantSchemaDef, schemaTypescriptFileToInstantSchema, version, translatePlanSteps, PlatformApi, ProgressPromise, exchangeCodeForToken, exchangeRefreshToken, i, };
12
12
  export { diffSchemas, convertTxSteps, isRenamePromptItem, type RenameResolveFn, type MigrationTx, type MigrationTxSpecific, type MigrationTxTypes, type Identifier, } from './migrations.ts';
13
- export { formatKey, renderAttrCall, renderAttrProperty, renderEntityProperty, renderLinkValue, renderLinkProperty, renderLinksObject, } from './schemaCodegen.ts';
14
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,YAAY,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EACL,KAAK,wBAAwB,EAC7B,4BAA4B,EAC5B,cAAc,EACd,qBAAqB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,2BAA2B,EAC3B,WAAW,EACX,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mCAAmC,EAAE,MAAM,wBAAwB,CAAC;AAE7E,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,CAAC,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;A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C,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,YAAY,EACZ,iBAAiB,EACjB,4BAA4B,EAC5B,cAAc,EACd,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,EAC3B,mCAAmC,EACnC,OAAO,EACP,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,CAAC,GACF,CAAC;AAEF,OAAO,EACL,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,UAAU,GAChB,MAAM,iBAAiB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -10,5 +10,4 @@ import { i } from '@instantdb/core';
10
10
  import { exchangeCodeForToken, exchangeRefreshToken } from "./serverOAuth.js";
11
11
  export { OAuthHandler, InstantOAuthError, generateSchemaTypescriptFile, validateSchema, SchemaValidationError, generatePermsTypescriptFile, apiSchemaToInstantSchemaDef, schemaTypescriptFileToInstantSchema, version, translatePlanSteps, PlatformApi, ProgressPromise, exchangeCodeForToken, exchangeRefreshToken, i, };
12
12
  export { diffSchemas, convertTxSteps, isRenamePromptItem, } from "./migrations.js";
13
- export { formatKey, renderAttrCall, renderAttrProperty, renderEntityProperty, renderLinkValue, renderLinkProperty, renderLinksObject, } from "./schemaCodegen.js";
14
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAGL,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAEL,4BAA4B,EAC5B,cAAc,EACd,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,2BAA2B,EAC3B,WAAW,EACX,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mCAAmC,EAAE,MAAM,wBAAwB,CAAC;AAE7E,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,CAAC,EAAqB,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAML,YAAY,EACZ,iBAAiB,EACjB,4BAA4B,EAC5B,cAAc,EACd,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,EAC3B,mCAAmC,EACnC,OAAO,EACP,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,CAAC,GACF,CAAC;AAEF,OAAO,EACL,WAAW,EACX,cAAc,EACd,kBAAkB,GAMnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,SAAS,EACT,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC","sourcesContent":["import { InstantOAuthError, type OAuthScope } from './oauthCommon.ts';\nimport {\n type InstantDBOAuthAccessToken,\n type OAuthHandlerConfig,\n OAuthHandler,\n} from './oauth.ts';\nimport { generatePermsTypescriptFile } from './perms.ts';\nimport {\n type InstantAPIPlatformSchema,\n generateSchemaTypescriptFile,\n validateSchema,\n SchemaValidationError,\n} from './schema.ts';\nimport {\n apiSchemaToInstantSchemaDef,\n PlatformApi,\n translatePlanSteps,\n} from './api.ts';\nimport { schemaTypescriptFileToInstantSchema } from './typescript-schema.ts';\n\nimport version from './version.ts';\nimport { ProgressPromise } from './ProgressPromise.ts';\nimport { i, type InstantRules } from '@instantdb/core';\nimport { exchangeCodeForToken, exchangeRefreshToken } from './serverOAuth.ts';\n\nexport {\n type InstantAPIPlatformSchema,\n type InstantDBOAuthAccessToken,\n type OAuthHandlerConfig,\n type OAuthScope,\n type InstantRules,\n OAuthHandler,\n InstantOAuthError,\n generateSchemaTypescriptFile,\n validateSchema,\n SchemaValidationError,\n generatePermsTypescriptFile,\n apiSchemaToInstantSchemaDef,\n schemaTypescriptFileToInstantSchema,\n version,\n translatePlanSteps,\n PlatformApi,\n ProgressPromise,\n exchangeCodeForToken,\n exchangeRefreshToken,\n i,\n};\n\nexport {\n diffSchemas,\n convertTxSteps,\n isRenamePromptItem,\n type RenameResolveFn,\n type MigrationTx,\n type MigrationTxSpecific,\n type MigrationTxTypes,\n type Identifier,\n} from './migrations.ts';\n\nexport {\n formatKey,\n renderAttrCall,\n renderAttrProperty,\n renderEntityProperty,\n renderLinkValue,\n renderLinkProperty,\n renderLinksObject,\n} from './schemaCodegen.ts';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAGL,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAEL,4BAA4B,EAC5B,cAAc,EACd,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,2BAA2B,EAC3B,WAAW,EACX,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mCAAmC,EAAE,MAAM,wBAAwB,CAAC;AAE7E,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,CAAC,EAAqB,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAML,YAAY,EACZ,iBAAiB,EACjB,4BAA4B,EAC5B,cAAc,EACd,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,EAC3B,mCAAmC,EACnC,OAAO,EACP,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,CAAC,GACF,CAAC;AAEF,OAAO,EACL,WAAW,EACX,cAAc,EACd,kBAAkB,GAMnB,MAAM,iBAAiB,CAAC","sourcesContent":["import { InstantOAuthError, type OAuthScope } from './oauthCommon.ts';\nimport {\n type InstantDBOAuthAccessToken,\n type OAuthHandlerConfig,\n OAuthHandler,\n} from './oauth.ts';\nimport { generatePermsTypescriptFile } from './perms.ts';\nimport {\n type InstantAPIPlatformSchema,\n generateSchemaTypescriptFile,\n validateSchema,\n SchemaValidationError,\n} from './schema.ts';\nimport {\n apiSchemaToInstantSchemaDef,\n PlatformApi,\n translatePlanSteps,\n} from './api.ts';\nimport { schemaTypescriptFileToInstantSchema } from './typescript-schema.ts';\n\nimport version from './version.ts';\nimport { ProgressPromise } from './ProgressPromise.ts';\nimport { i, type InstantRules } from '@instantdb/core';\nimport { exchangeCodeForToken, exchangeRefreshToken } from './serverOAuth.ts';\n\nexport {\n type InstantAPIPlatformSchema,\n type InstantDBOAuthAccessToken,\n type OAuthHandlerConfig,\n type OAuthScope,\n type InstantRules,\n OAuthHandler,\n InstantOAuthError,\n generateSchemaTypescriptFile,\n validateSchema,\n SchemaValidationError,\n generatePermsTypescriptFile,\n apiSchemaToInstantSchemaDef,\n schemaTypescriptFileToInstantSchema,\n version,\n translatePlanSteps,\n PlatformApi,\n ProgressPromise,\n exchangeCodeForToken,\n exchangeRefreshToken,\n i,\n};\n\nexport {\n diffSchemas,\n convertTxSteps,\n isRenamePromptItem,\n type RenameResolveFn,\n type MigrationTx,\n type MigrationTxSpecific,\n type MigrationTxTypes,\n type Identifier,\n} from './migrations.ts';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,aAAa,EACb,wBAAwB,EACxB,cAAc,EAIf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAIL,gBAAgB,EACjB,MAAM,WAAW,CAAC;AAOnB,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,UAAU,CAAC;IACjB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,aAAa,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,aAAa,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,OAAO,CAAC;IACd,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,cAAc,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,8B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E,GAAG,CAAC,MAAM,CAAC,CAAC,SA8DrD,CAAC"}
@@ -1,10 +1,16 @@
1
- import { indentLines, joinWithTrailingSep, sortedEntries, } from "./util.js";
2
- import { formatKey, renderEntityProperty, renderLinksObject, } from "./schemaCodegen.js";
1
+ import { indentLines, joinWithTrailingSep, sortedEntries, formatKey, } from "./util.js";
2
+ function attrDefToCodeString([name, attr]) {
3
+ var _a;
4
+ const type = ((_a = attr.metadata.derivedType) === null || _a === void 0 ? void 0 : _a.type) || attr.valueType || 'any';
5
+ const unique = attr.config.unique ? '.unique()' : '';
6
+ const index = attr.config.indexed ? '.indexed()' : '';
7
+ const required = attr.required ? '' : '.optional()';
8
+ return `${formatKey(name)}: i.${type}()${unique}${index}${required}`;
9
+ }
3
10
  function entityDefToCodeStr(name, edef) {
4
- return renderEntityProperty(name, edef.attrs, {
5
- keyOptions: { alwaysQuote: true, quote: '"' },
6
- trailingComma: true,
7
- });
11
+ const attrBlock = joinWithTrailingSep(sortedEntries(edef.attrs).map(attrDefToCodeString), ',\n', ',');
12
+ // a block of code for each entity
13
+ return `${formatKey(name)}: i.entity({${attrBlock.length ? '\n' : ''}${indentLines(attrBlock, 2)}${attrBlock.length ? '\n' : ''}})`;
8
14
  }
9
15
  export function identEtype(ident) {
10
16
  return ident[1];
@@ -48,7 +54,7 @@ function roomDefToCodeStr(room) {
48
54
  ret += `\n${indentLines(entityDefToCodeStr('presence', room.presence), 4)},`;
49
55
  }
50
56
  if (room.topics) {
51
- ret += `\n ${formatKey('topics', { alwaysQuote: true, quote: '"' })}: {`;
57
+ ret += `\n "topics": {`;
52
58
  for (const [topicName, topicConfig] of Object.entries(room.topics)) {
53
59
  ret += `\n${indentLines(entityDefToCodeStr(topicName, topicConfig), 6)},`;
54
60
  }
@@ -60,7 +66,7 @@ function roomDefToCodeStr(room) {
60
66
  function roomsCodeStr(rooms) {
61
67
  let ret = '{';
62
68
  for (const [roomType, roomDef] of Object.entries(rooms)) {
63
- ret += `\n ${formatKey(roomType, { alwaysQuote: true, quote: '"' })}: ${roomDefToCodeStr(roomDef)},`;
69
+ ret += `\n ${formatKey(roomType)}: ${roomDefToCodeStr(roomDef)},`;
64
70
  }
65
71
  ret += ret === '{' ? '}' : '\n}';
66
72
  return ret;
@@ -83,11 +89,7 @@ export function generateSchemaTypescriptFile(prevSchema, newSchema, instantModul
83
89
  // Take a look at this schema, and if everything looks good,
84
90
  // run \`push schema\` again to enforce the types.`
85
91
  : '';
86
- const linksEntriesCode = renderLinksObject(newSchema.links, {
87
- keyOptions: { alwaysQuote: true, quote: '"' },
88
- stringQuote: '"',
89
- style: 'json',
90
- });
92
+ const linksEntriesCode = JSON.stringify(newSchema.links, null, 2).trim();
91
93
  // rooms
92
94
  const rooms = (prevSchema === null || prevSchema === void 0 ? void 0 : prevSchema.rooms) || {};
93
95
  const roomsCode = roomsCodeStr(rooms);
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,aAAa,GAEd,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAiP5B,SAAS,kBAAkB,CACzB,IAAY,EACZ,IAIC;IAED,OAAO,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE;QAC5C,UAAU,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE;QAC7C,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAqB;IAC9C,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAqB;IAC9C,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,OAA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,\n RoomsDef,\n} from '@instantdb/core';\n\nimport {\n indentLines,\n joinWithTrailingSep,\n sortedEntries,\n GenericSchemaDef,\n} from './util.ts';\nimport {\n formatKey,\n renderEntityProperty,\n renderLinksObject,\n} from './schemaCodegen.ts';\n\nexport type InstantAPIPlatformSchema = {\n refs: Record<string, InstantDBAttr>;\n blobs: Record<string, Record<string, InstantDBAttr>>;\n};\n\nexport type InstantAPISchemaPlanAddAttrStep = {\n type: 'add-attr';\n friendlyDescription: string;\n attr: InstantDBAttr;\n};\n\nexport type InstantAPISchemaPlanDeleteAttrStep = {\n type: 'delete-attr';\n friendlyDescription: string;\n attrId: string;\n};\n\nexport type InstantAPISchemaPlanUpdateAttrStep = {\n type: 'update-attr';\n friendlyDescription: string;\n attr: InstantDBAttr;\n};\n\nexport type InstantAPISchemaPlanIndexStep = {\n type: 'index';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveIndexStep = {\n type: 'remove-index';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanUniqueStep = {\n type: 'unique';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveUniqueStep = {\n type: 'remove-unique';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRequiredStep = {\n type: 'required';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveRequiredStep = {\n type: 'remove-required';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanCheckDataTypeStep = {\n type: 'check-data-type';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n checkedDataType: InstantDBCheckedDataType;\n};\n\nexport type InstantAPISchemaPlanRemoveDataTypeStep = {\n type: 'remove-data-type';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\ntype InstantBackgroundSchemaBaseJob = {\n id: string;\n createdAt: Date;\n updatedAt: Date;\n status: 'completed' | 'waiting' | 'processing' | 'errored';\n workEstimate: number | null;\n workCompleted: number | null;\n error?:\n | 'invalid-triple-error'\n | 'invalid-attr-state-error'\n | 'triple-not-unique-error'\n | 'triple-too-large-error'\n | 'missing-required-error'\n | 'unexpected-error';\n invalidTriplesSample?: {\n entityId: string;\n value: any;\n jsonType:\n | 'string'\n | 'number'\n | 'boolean'\n | 'null'\n | 'object'\n | 'array'\n | 'date';\n }[];\n};\n\ntype InstantBackgroundSchemaBaseJobWithInvalidTriples =\n InstantBackgroundSchemaBaseJob & {\n invalidTriplesSample?: {\n entityId: string;\n value: any;\n jsonType:\n | 'string'\n | 'number'\n | 'boolean'\n | 'null'\n | 'object'\n | 'array'\n | 'date';\n }[];\n };\n\nexport interface InstantBackgroundSchemaRemoveDataTypeJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-data-type';\n}\n\nexport interface InstantBackgroundSchemaCheckDataTypeJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'check-data-type';\n checkedDataType: InstantDBCheckedDataType;\n}\n\nexport interface InstantBackgroundSchemaAddIndexJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'index';\n}\n\nexport interface InstantBackgroundSchemaRemoveIndexJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-index';\n}\n\nexport interface InstantBackgroundSchemaAddUniqueJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'unique';\n invalidUniqueValue?: any;\n}\n\nexport interface InstantBackgroundSchemaRemoveUniqueJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-unique';\n}\n\nexport interface InstantBackgroundSchemaAddRequiredJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'required';\n}\n\nexport interface InstantBackgroundSchemaRemoveRequiredJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-required';\n}\n\nexport type InstantAPISchemaPlanStep =\n | InstantAPISchemaPlanAddAttrStep\n | InstantAPISchemaPlanDeleteAttrStep\n | InstantAPISchemaPlanUpdateAttrStep\n | InstantAPISchemaPlanIndexStep\n | InstantAPISchemaPlanRemoveIndexStep\n | InstantAPISchemaPlanUniqueStep\n | InstantAPISchemaPlanRemoveUniqueStep\n | InstantAPISchemaPlanRequiredStep\n | InstantAPISchemaPlanRemoveRequiredStep\n | InstantAPISchemaPlanCheckDataTypeStep\n | InstantAPISchemaPlanRemoveDataTypeStep;\n\ntype BackgroundJobByStep = {\n index: InstantBackgroundSchemaAddIndexJob;\n 'remove-index': InstantBackgroundSchemaRemoveIndexJob;\n unique: InstantBackgroundSchemaAddUniqueJob;\n 'remove-unique': InstantBackgroundSchemaRemoveUniqueJob;\n required: InstantBackgroundSchemaAddRequiredJob;\n 'remove-required': InstantBackgroundSchemaRemoveRequiredJob;\n 'check-data-type': InstantBackgroundSchemaCheckDataTypeJob;\n 'remove-data-type': InstantBackgroundSchemaRemoveDataTypeJob;\n};\n\n// Adds the proper flavor of the backgroundJob type to the steps\n// that run in the background\nexport type WithBackgroundJob<P extends { type: string }> =\n P['type'] extends keyof BackgroundJobByStep\n ? P & { backgroundJob: BackgroundJobByStep[P['type']] }\n : P;\n\nexport type InstantAPISchemaPushAddAttrStep =\n WithBackgroundJob<InstantAPISchemaPlanAddAttrStep>;\n\nexport type InstantAPISchemaPushUpdateAttrStep =\n WithBackgroundJob<InstantAPISchemaPlanUpdateAttrStep>;\n\nexport type InstantAPISchemaPushIndexStep =\n WithBackgroundJob<InstantAPISchemaPlanIndexStep>;\n\nexport type InstantAPISchemaPushRemoveIndexStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveIndexStep>;\n\nexport type InstantAPISchemaPushUniqueStep =\n WithBackgroundJob<InstantAPISchemaPlanUniqueStep>;\n\nexport type InstantAPISchemaPushRemoveUniqueStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveUniqueStep>;\n\nexport type InstantAPISchemaPushRequiredStep =\n WithBackgroundJob<InstantAPISchemaPlanRequiredStep>;\n\nexport type InstantAPISchemaPushRemoveRequiredStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveRequiredStep>;\n\nexport type InstantAPISchemaPushCheckDataTypeStep =\n WithBackgroundJob<InstantAPISchemaPlanCheckDataTypeStep>;\n\nexport type InstantAPISchemaPushRemoveDataTypeStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveDataTypeStep>;\n\nexport type InstantAPISchemaPushStep =\n | InstantAPISchemaPushAddAttrStep\n | InstantAPISchemaPushUpdateAttrStep\n | InstantAPISchemaPushIndexStep\n | InstantAPISchemaPushRemoveIndexStep\n | InstantAPISchemaPushUniqueStep\n | InstantAPISchemaPushRemoveUniqueStep\n | InstantAPISchemaPushRequiredStep\n | InstantAPISchemaPushRemoveRequiredStep\n | InstantAPISchemaPushCheckDataTypeStep\n | InstantAPISchemaPushRemoveDataTypeStep;\n\nfunction entityDefToCodeStr(\n name: string,\n edef: EntityDef<\n AttrsDefs,\n Record<string, LinkAttrDef<CardinalityKind, string>>,\n any\n >,\n) {\n return renderEntityProperty(name, edef.attrs, {\n keyOptions: { alwaysQuote: true, quote: '\"' },\n trailingComma: true,\n });\n}\n\nexport function identEtype(ident: InstantDBIdent) {\n return ident[1];\n}\n\nexport function identLabel(ident: InstantDBIdent) {\n return ident[2];\n}\n\nexport function identName(ident: InstantDBIdent) {\n return `${identEtype(ident)}.${identLabel(ident)}`;\n}\n\nexport function attrFwdLabel(attr: InstantDBAttr) {\n return attr['forward-identity']?.[2];\n}\n\nexport function attrFwdEtype(attr: InstantDBAttr) {\n return attr['forward-identity']?.[1];\n}\n\nexport function attrRevLabel(attr: InstantDBAttr) {\n return attr['reverse-identity']?.[2];\n}\n\nexport function attrRevEtype(attr: InstantDBAttr) {\n return attr['reverse-identity']?.[1];\n}\n\nexport function attrFwdName(attr: InstantDBAttr) {\n return `${attrFwdEtype(attr)}.${attrFwdLabel(attr)}`;\n}\n\nexport function attrRevName(attr: InstantDBAttr) {\n if (attr['reverse-identity']) {\n return `${attrRevEtype(attr)}.${attrRevLabel(attr)}`;\n }\n}\n\nfunction easyPlural(strn: string, n: number) {\n return n === 1 ? strn : strn + 's';\n}\n\nfunction roomDefToCodeStr(room: RoomsDef[string]) {\n let ret = '{';\n\n if (room.presence) {\n ret += `\\n${indentLines(entityDefToCodeStr('presence', room.presence), 4)},`;\n }\n\n if (room.topics) {\n ret += `\\n ${formatKey('topics', { alwaysQuote: true, quote: '\"' })}: {`;\n\n for (const [topicName, topicConfig] of Object.entries(room.topics)) {\n ret += `\\n${indentLines(entityDefToCodeStr(topicName, topicConfig), 6)},`;\n }\n ret += `\\n }`;\n }\n\n ret += ret === '{' ? '}' : '\\n }';\n\n return ret;\n}\n\nfunction roomsCodeStr(rooms: RoomsDef) {\n let ret = '{';\n\n for (const [roomType, roomDef] of Object.entries(rooms)) {\n ret += `\\n ${formatKey(roomType, { alwaysQuote: true, quote: '\"' })}: ${roomDefToCodeStr(roomDef)},`;\n }\n ret += ret === '{' ? '}' : '\\n}';\n\n return ret;\n}\n\nexport function generateSchemaTypescriptFile(\n prevSchema: GenericSchemaDef | null | undefined,\n newSchema: GenericSchemaDef,\n instantModuleName: string,\n): string {\n // entities\n const entitiesEntriesCode = joinWithTrailingSep(\n sortedEntries(newSchema.entities).map(([etype, entityDef]) =>\n entityDefToCodeStr(etype, entityDef),\n ),\n ',\\n',\n ',',\n );\n\n const inferredAttrs: DataAttrDef<string, boolean, boolean>[] = [];\n\n for (const entity of Object.values(newSchema.entities)) {\n for (const attr of Object.values(entity.attrs)) {\n if ((attr.metadata.derivedType as any)?.origin === 'inferred') {\n inferredAttrs.push(attr);\n }\n }\n }\n\n const entitiesObjCode = `{\\n${indentLines(entitiesEntriesCode, 2)}\\n}`;\n\n const entitiesComment =\n inferredAttrs.length > 0\n ? `// We inferred ${inferredAttrs.length} ${easyPlural('attribute', inferredAttrs.length)}!\n// Take a look at this schema, and if everything looks good,\n// run \\`push schema\\` again to enforce the types.`\n : '';\n\n const linksEntriesCode = renderLinksObject(newSchema.links, {\n keyOptions: { alwaysQuote: true, quote: '\"' },\n stringQuote: '\"',\n style: 'json',\n });\n\n // rooms\n const rooms = prevSchema?.rooms || {};\n const roomsCode = roomsCodeStr(rooms);\n const kv = (k: string, v: string, comment?: string) => {\n const res = comment ? `${comment}\\n${k}: ${v}` : `${k}: ${v}`;\n return indentLines(res, 2);\n };\n\n const code = `// Docs: https://www.instantdb.com/docs/modeling-data\n\nimport { i } from \"${instantModuleName ?? '@instantdb/core'}\";\n\nconst _schema = i.schema({\n${kv('entities', entitiesObjCode, entitiesComment)},\n${kv('links', linksEntriesCode)},\n${kv('rooms', roomsCode)}\n});\n\n// This helps Typescript display nicer intellisense\ntype _AppSchema = typeof _schema;\ninterface AppSchema extends _AppSchema {}\nconst schema: AppSchema = _schema;\n\nexport type { AppSchema }\nexport default schema;\n`;\n\n return code;\n}\n\nexport class SchemaValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SchemaValidationError';\n }\n}\n\nexport const validateSchema = (\n schema: GenericSchemaDef,\n systemCatalogIdentNames: Record<string, Set<string>>,\n) => {\n const entityNames = Object.keys(schema.entities);\n\n for (const [etype, entityDef] of Object.entries(schema.entities)) {\n if (!etype.startsWith('$')) continue;\n if (!systemCatalogIdentNames[etype]) {\n throw new SchemaValidationError(\n 'The $ keyword is reserved for system namespaces.' +\n `\\nYou can't create '${etype}'. Perhaps call it '${etype.slice(1)}' instead?`,\n );\n }\n for (const [attrName, attrDef] of Object.entries(entityDef.attrs)) {\n if (systemCatalogIdentNames[etype].has(attrName)) {\n continue;\n }\n if (attrDef.required) {\n throw new SchemaValidationError(\n `The '${etype}' namespace is managed by the system and can't modify required constraints yet.` +\n `\\nMake sure to set ${etype}.${attrName} as optional.` +\n `\\n i.e { ${attrName}: i.${attrDef.valueType}().optional() }`,\n );\n }\n }\n }\n\n for (const link of Object.values(schema.links)) {\n if (\n systemCatalogIdentNames[link.forward.on] &&\n !systemCatalogIdentNames[link.forward.on].has(link.forward.label) &&\n link.forward.required\n ) {\n throw new SchemaValidationError(\n `The ${link.forward.on} namespace is managed by the system and can't modify required constraints yet.` +\n `\\nMake sure to set ${link.forward.on}${link.forward.label} as 'optional'.` +\n `\\n i.e { 'on': '${link.forward.on}', 'label': ${link.forward.label}, 'required': false }`,\n );\n }\n\n if (link.forward.has === 'many' && link.forward.onDelete === 'cascade') {\n throw new SchemaValidationError(\n `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: \"cascade\" with has: \"many\"`,\n );\n }\n if (link.reverse.has === 'many' && link.reverse.onDelete === 'cascade') {\n throw new SchemaValidationError(\n `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: \"cascade\" with has: \"many\"`,\n );\n }\n\n const linkDisplay = `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label}`;\n if (!entityNames.includes(link.forward.on)) {\n throw new SchemaValidationError(\n `${linkDisplay} connects to non existing entity \"${link.forward.on}\".`,\n );\n }\n if (!entityNames.includes(link.reverse.on)) {\n throw new SchemaValidationError(\n `${linkDisplay} connects to non existing entity \"${link.forward.on}\".`,\n );\n }\n }\n};\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,SAAS,GAEV,MAAM,WAAW,CAAC;AAiPnB,SAAS,mBAAmB,CAAC,CAAC,IAAI,EAAE,IAAI,CAGvC;;IACC,MAAM,IAAI,GACR,CAAA,MAAC,IAAI,CAAC,QAAQ,CAAC,WAAmB,0CAAE,IAAI,KAAI,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC;IACtE,MAAM,MAAM,GAAG,IAAI,CAAC,M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I,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,2CAA2C,CAC9H,CAAC;QACJ,CAAC;QAED,MAAM,WAAW,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACzG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,qBAAqB,CAC7B,GAAG,WAAW,qCAAqC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CACvE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,qBAAqB,CAC7B,GAAG,WAAW,qCAAqC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CACvE,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n AttrsDefs,\n CardinalityKind,\n DataAttrDef,\n EntityDef,\n InstantDBAttr,\n InstantDBCheckedDataType,\n InstantDBIdent,\n InstantSchemaDef,\n LinkAttrDef,\n RoomsDef,\n} from '@instantdb/core';\n\nimport {\n indentLines,\n joinWithTrailingSep,\n sortedEntries,\n formatKey,\n GenericSchemaDef,\n} from './util.ts';\n\nexport type InstantAPIPlatformSchema = {\n refs: Record<string, InstantDBAttr>;\n blobs: Record<string, Record<string, InstantDBAttr>>;\n};\n\nexport type InstantAPISchemaPlanAddAttrStep = {\n type: 'add-attr';\n friendlyDescription: string;\n attr: InstantDBAttr;\n};\n\nexport type InstantAPISchemaPlanDeleteAttrStep = {\n type: 'delete-attr';\n friendlyDescription: string;\n attrId: string;\n};\n\nexport type InstantAPISchemaPlanUpdateAttrStep = {\n type: 'update-attr';\n friendlyDescription: string;\n attr: InstantDBAttr;\n};\n\nexport type InstantAPISchemaPlanIndexStep = {\n type: 'index';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveIndexStep = {\n type: 'remove-index';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanUniqueStep = {\n type: 'unique';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveUniqueStep = {\n type: 'remove-unique';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRequiredStep = {\n type: 'required';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanRemoveRequiredStep = {\n type: 'remove-required';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\nexport type InstantAPISchemaPlanCheckDataTypeStep = {\n type: 'check-data-type';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n checkedDataType: InstantDBCheckedDataType;\n};\n\nexport type InstantAPISchemaPlanRemoveDataTypeStep = {\n type: 'remove-data-type';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: InstantDBIdent;\n};\n\ntype InstantBackgroundSchemaBaseJob = {\n id: string;\n createdAt: Date;\n updatedAt: Date;\n status: 'completed' | 'waiting' | 'processing' | 'errored';\n workEstimate: number | null;\n workCompleted: number | null;\n error?:\n | 'invalid-triple-error'\n | 'invalid-attr-state-error'\n | 'triple-not-unique-error'\n | 'triple-too-large-error'\n | 'missing-required-error'\n | 'unexpected-error';\n invalidTriplesSample?: {\n entityId: string;\n value: any;\n jsonType:\n | 'string'\n | 'number'\n | 'boolean'\n | 'null'\n | 'object'\n | 'array'\n | 'date';\n }[];\n};\n\ntype InstantBackgroundSchemaBaseJobWithInvalidTriples =\n InstantBackgroundSchemaBaseJob & {\n invalidTriplesSample?: {\n entityId: string;\n value: any;\n jsonType:\n | 'string'\n | 'number'\n | 'boolean'\n | 'null'\n | 'object'\n | 'array'\n | 'date';\n }[];\n };\n\nexport interface InstantBackgroundSchemaRemoveDataTypeJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-data-type';\n}\n\nexport interface InstantBackgroundSchemaCheckDataTypeJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'check-data-type';\n checkedDataType: InstantDBCheckedDataType;\n}\n\nexport interface InstantBackgroundSchemaAddIndexJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'index';\n}\n\nexport interface InstantBackgroundSchemaRemoveIndexJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-index';\n}\n\nexport interface InstantBackgroundSchemaAddUniqueJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'unique';\n invalidUniqueValue?: any;\n}\n\nexport interface InstantBackgroundSchemaRemoveUniqueJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-unique';\n}\n\nexport interface InstantBackgroundSchemaAddRequiredJob\n extends InstantBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'required';\n}\n\nexport interface InstantBackgroundSchemaRemoveRequiredJob\n extends InstantBackgroundSchemaBaseJob {\n type: 'remove-required';\n}\n\nexport type InstantAPISchemaPlanStep =\n | InstantAPISchemaPlanAddAttrStep\n | InstantAPISchemaPlanDeleteAttrStep\n | InstantAPISchemaPlanUpdateAttrStep\n | InstantAPISchemaPlanIndexStep\n | InstantAPISchemaPlanRemoveIndexStep\n | InstantAPISchemaPlanUniqueStep\n | InstantAPISchemaPlanRemoveUniqueStep\n | InstantAPISchemaPlanRequiredStep\n | InstantAPISchemaPlanRemoveRequiredStep\n | InstantAPISchemaPlanCheckDataTypeStep\n | InstantAPISchemaPlanRemoveDataTypeStep;\n\ntype BackgroundJobByStep = {\n index: InstantBackgroundSchemaAddIndexJob;\n 'remove-index': InstantBackgroundSchemaRemoveIndexJob;\n unique: InstantBackgroundSchemaAddUniqueJob;\n 'remove-unique': InstantBackgroundSchemaRemoveUniqueJob;\n required: InstantBackgroundSchemaAddRequiredJob;\n 'remove-required': InstantBackgroundSchemaRemoveRequiredJob;\n 'check-data-type': InstantBackgroundSchemaCheckDataTypeJob;\n 'remove-data-type': InstantBackgroundSchemaRemoveDataTypeJob;\n};\n\n// Adds the proper flavor of the backgroundJob type to the steps\n// that run in the background\nexport type WithBackgroundJob<P extends { type: string }> =\n P['type'] extends keyof BackgroundJobByStep\n ? P & { backgroundJob: BackgroundJobByStep[P['type']] }\n : P;\n\nexport type InstantAPISchemaPushAddAttrStep =\n WithBackgroundJob<InstantAPISchemaPlanAddAttrStep>;\n\nexport type InstantAPISchemaPushUpdateAttrStep =\n WithBackgroundJob<InstantAPISchemaPlanUpdateAttrStep>;\n\nexport type InstantAPISchemaPushIndexStep =\n WithBackgroundJob<InstantAPISchemaPlanIndexStep>;\n\nexport type InstantAPISchemaPushRemoveIndexStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveIndexStep>;\n\nexport type InstantAPISchemaPushUniqueStep =\n WithBackgroundJob<InstantAPISchemaPlanUniqueStep>;\n\nexport type InstantAPISchemaPushRemoveUniqueStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveUniqueStep>;\n\nexport type InstantAPISchemaPushRequiredStep =\n WithBackgroundJob<InstantAPISchemaPlanRequiredStep>;\n\nexport type InstantAPISchemaPushRemoveRequiredStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveRequiredStep>;\n\nexport type InstantAPISchemaPushCheckDataTypeStep =\n WithBackgroundJob<InstantAPISchemaPlanCheckDataTypeStep>;\n\nexport type InstantAPISchemaPushRemoveDataTypeStep =\n WithBackgroundJob<InstantAPISchemaPlanRemoveDataTypeStep>;\n\nexport type InstantAPISchemaPushStep =\n | InstantAPISchemaPushAddAttrStep\n | InstantAPISchemaPushUpdateAttrStep\n | InstantAPISchemaPushIndexStep\n | InstantAPISchemaPushRemoveIndexStep\n | InstantAPISchemaPushUniqueStep\n | InstantAPISchemaPushRemoveUniqueStep\n | InstantAPISchemaPushRequiredStep\n | InstantAPISchemaPushRemoveRequiredStep\n | InstantAPISchemaPushCheckDataTypeStep\n | InstantAPISchemaPushRemoveDataTypeStep;\n\nfunction attrDefToCodeString([name, attr]: [\n string,\n DataAttrDef<string, boolean, boolean>,\n]) {\n const type =\n (attr.metadata.derivedType as any)?.type || attr.valueType || 'any';\n const unique = attr.config.unique ? '.unique()' : '';\n const index = attr.config.indexed ? '.indexed()' : '';\n const required = attr.required ? '' : '.optional()';\n return `${formatKey(name)}: i.${type}()${unique}${index}${required}`;\n}\n\nfunction entityDefToCodeStr(\n name: string,\n edef: EntityDef<\n AttrsDefs,\n Record<string, LinkAttrDef<CardinalityKind, string>>,\n any\n >,\n) {\n const attrBlock = joinWithTrailingSep(\n sortedEntries(edef.attrs).map(attrDefToCodeString),\n ',\\n',\n ',',\n );\n\n // a block of code for each entity\n return `${formatKey(name)}: i.entity({${attrBlock.length ? '\\n' : ''}${indentLines(attrBlock, 2)}${attrBlock.length ? '\\n' : ''}})`;\n}\n\nexport function identEtype(ident: InstantDBIdent) {\n return ident[1];\n}\n\nexport function identLabel(ident: InstantDBIdent) {\n return ident[2];\n}\n\nexport function identName(ident: InstantDBIdent) {\n return `${identEtype(ident)}.${identLabel(ident)}`;\n}\n\nexport function attrFwdLabel(attr: InstantDBAttr) {\n return attr['forward-identity']?.[2];\n}\n\nexport function attrFwdEtype(attr: InstantDBAttr) {\n return attr['forward-identity']?.[1];\n}\n\nexport function attrRevLabel(attr: InstantDBAttr) {\n return attr['reverse-identity']?.[2];\n}\n\nexport function attrRevEtype(attr: InstantDBAttr) {\n return attr['reverse-identity']?.[1];\n}\n\nexport function attrFwdName(attr: InstantDBAttr) {\n return `${attrFwdEtype(attr)}.${attrFwdLabel(attr)}`;\n}\n\nexport function attrRevName(attr: InstantDBAttr) {\n if (attr['reverse-identity']) {\n return `${attrRevEtype(attr)}.${attrRevLabel(attr)}`;\n }\n}\n\nfunction easyPlural(strn: string, n: number) {\n return n === 1 ? strn : strn + 's';\n}\n\nfunction roomDefToCodeStr(room: RoomsDef[string]) {\n let ret = '{';\n\n if (room.presence) {\n ret += `\\n${indentLines(entityDefToCodeStr('presence', room.presence), 4)},`;\n }\n\n if (room.topics) {\n ret += `\\n \"topics\": {`;\n\n for (const [topicName, topicConfig] of Object.entries(room.topics)) {\n ret += `\\n${indentLines(entityDefToCodeStr(topicName, topicConfig), 6)},`;\n }\n ret += `\\n }`;\n }\n\n ret += ret === '{' ? '}' : '\\n }';\n\n return ret;\n}\n\nfunction roomsCodeStr(rooms: RoomsDef) {\n let ret = '{';\n\n for (const [roomType, roomDef] of Object.entries(rooms)) {\n ret += `\\n ${formatKey(roomType)}: ${roomDefToCodeStr(roomDef)},`;\n }\n ret += ret === '{' ? '}' : '\\n}';\n\n return ret;\n}\n\nexport function generateSchemaTypescriptFile(\n prevSchema: GenericSchemaDef | null | undefined,\n newSchema: GenericSchemaDef,\n instantModuleName: string,\n): string {\n // entities\n const entitiesEntriesCode = joinWithTrailingSep(\n sortedEntries(newSchema.entities).map(([etype, entityDef]) =>\n entityDefToCodeStr(etype, entityDef),\n ),\n ',\\n',\n ',',\n );\n\n const inferredAttrs: DataAttrDef<string, boolean, boolean>[] = [];\n\n for (const entity of Object.values(newSchema.entities)) {\n for (const attr of Object.values(entity.attrs)) {\n if ((attr.metadata.derivedType as any)?.origin === 'inferred') {\n inferredAttrs.push(attr);\n }\n }\n }\n\n const entitiesObjCode = `{\\n${indentLines(entitiesEntriesCode, 2)}\\n}`;\n\n const entitiesComment =\n inferredAttrs.length > 0\n ? `// We inferred ${inferredAttrs.length} ${easyPlural('attribute', inferredAttrs.length)}!\n// Take a look at this schema, and if everything looks good,\n// run \\`push schema\\` again to enforce the types.`\n : '';\n\n const linksEntriesCode = JSON.stringify(newSchema.links, null, 2).trim();\n\n // rooms\n const rooms = prevSchema?.rooms || {};\n const roomsCode = roomsCodeStr(rooms);\n const kv = (k: string, v: string, comment?: string) => {\n const res = comment ? `${comment}\\n${k}: ${v}` : `${k}: ${v}`;\n return indentLines(res, 2);\n };\n\n const code = `// Docs: https://www.instantdb.com/docs/modeling-data\n\nimport { i } from \"${instantModuleName ?? '@instantdb/core'}\";\n\nconst _schema = i.schema({\n${kv('entities', entitiesObjCode, entitiesComment)},\n${kv('links', linksEntriesCode)},\n${kv('rooms', roomsCode)}\n});\n\n// This helps Typescript display nicer intellisense\ntype _AppSchema = typeof _schema;\ninterface AppSchema extends _AppSchema {}\nconst schema: AppSchema = _schema;\n\nexport type { AppSchema }\nexport default schema;\n`;\n\n return code;\n}\n\nexport class SchemaValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SchemaValidationError';\n }\n}\n\nexport const validateSchema = (\n schema: GenericSchemaDef,\n systemCatalogIdentNames: Record<string, Set<string>>,\n) => {\n const entityNames = Object.keys(schema.entities);\n\n for (const [etype, entityDef] of Object.entries(schema.entities)) {\n if (!etype.startsWith('$')) continue;\n if (!systemCatalogIdentNames[etype]) {\n throw new SchemaValidationError(\n 'The $ keyword is reserved for system namespaces.' +\n `\\nYou can't create '${etype}'. Perhaps call it '${etype.slice(1)}' instead?`,\n );\n }\n for (const [attrName, attrDef] of Object.entries(entityDef.attrs)) {\n if (systemCatalogIdentNames[etype].has(attrName)) {\n continue;\n }\n if (attrDef.required) {\n throw new SchemaValidationError(\n `The '${etype}' namespace is managed by the system and can't modify required constraints yet.` +\n `\\nMake sure to set ${etype}.${attrName} as optional.` +\n `\\n i.e { ${attrName}: i.${attrDef.valueType}().optional() }`,\n );\n }\n }\n }\n\n for (const link of Object.values(schema.links)) {\n if (\n systemCatalogIdentNames[link.forward.on] &&\n !systemCatalogIdentNames[link.forward.on].has(link.forward.label) &&\n link.forward.required\n ) {\n throw new SchemaValidationError(\n `The ${link.forward.on} namespace is managed by the system and can't modify required constraints yet.` +\n `\\nMake sure to set ${link.forward.on}${link.forward.label} as 'optional'.` +\n `\\n i.e { 'on': '${link.forward.on}', 'label': ${link.forward.label}, 'required': false }`,\n );\n }\n\n if (link.forward.has === 'many' && link.forward.onDelete === 'cascade') {\n throw new SchemaValidationError(\n `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: \"cascade\" with has: \"many\"`,\n );\n }\n if (link.reverse.has === 'many' && link.reverse.onDelete === 'cascade') {\n throw new SchemaValidationError(\n `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: \"cascade\" with has: \"many\"`,\n );\n }\n\n const linkDisplay = `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label}`;\n if (!entityNames.includes(link.forward.on)) {\n throw new SchemaValidationError(\n `${linkDisplay} connects to non existing entity \"${link.forward.on}\".`,\n );\n }\n if (!entityNames.includes(link.reverse.on)) {\n throw new SchemaValidationError(\n `${linkDisplay} connects to non existing entity \"${link.forward.on}\".`,\n );\n }\n }\n};\n"]}