@sidekickdb/platform 0.0.0 → 2.0.0

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.
Files changed (197) hide show
  1. package/.tshy/build.json +8 -0
  2. package/.tshy/commonjs.json +16 -0
  3. package/.tshy/esm.json +15 -0
  4. package/.turbo/turbo-build.log +50 -0
  5. package/LICENSE.md +202 -0
  6. package/NOTICE +27 -0
  7. package/README.md +444 -2
  8. package/__tests__/src/apiURI.test.ts +58 -0
  9. package/__tests__/src/backupDownload.test.ts +427 -0
  10. package/__tests__/src/backups.test.ts +168 -0
  11. package/__tests__/src/clerk.test.ts +13 -0
  12. package/__tests__/src/consts.test.ts +11 -0
  13. package/__tests__/src/migrations.test.ts +885 -0
  14. package/__tests__/src/perms.test.ts +102 -0
  15. package/__tests__/src/rename.test.ts +126 -0
  16. package/__tests__/src/schema.push.e2e.test.ts +186 -0
  17. package/__tests__/src/schema.test.ts +644 -0
  18. package/__tests__/src/typescript-schema.test.ts +117 -0
  19. package/dist/commonjs/ProgressPromise.d.ts +18 -0
  20. package/dist/commonjs/ProgressPromise.d.ts.map +1 -0
  21. package/dist/commonjs/ProgressPromise.js +77 -0
  22. package/dist/commonjs/ProgressPromise.js.map +1 -0
  23. package/dist/commonjs/api.d.ts +480 -0
  24. package/dist/commonjs/api.d.ts.map +1 -0
  25. package/dist/commonjs/api.js +1132 -0
  26. package/dist/commonjs/api.js.map +1 -0
  27. package/dist/commonjs/backupDownload.d.ts +89 -0
  28. package/dist/commonjs/backupDownload.d.ts.map +1 -0
  29. package/dist/commonjs/backupDownload.js +357 -0
  30. package/dist/commonjs/backupDownload.js.map +1 -0
  31. package/dist/commonjs/backups.d.ts +146 -0
  32. package/dist/commonjs/backups.d.ts.map +1 -0
  33. package/dist/commonjs/backups.js +248 -0
  34. package/dist/commonjs/backups.js.map +1 -0
  35. package/dist/commonjs/clerk.d.ts +2 -0
  36. package/dist/commonjs/clerk.d.ts.map +1 -0
  37. package/dist/commonjs/clerk.js +29 -0
  38. package/dist/commonjs/clerk.js.map +1 -0
  39. package/dist/commonjs/consts.d.ts +11 -0
  40. package/dist/commonjs/consts.d.ts.map +1 -0
  41. package/dist/commonjs/consts.js +17 -0
  42. package/dist/commonjs/consts.js.map +1 -0
  43. package/dist/commonjs/crypto.d.ts +4 -0
  44. package/dist/commonjs/crypto.d.ts.map +1 -0
  45. package/dist/commonjs/crypto.js +26 -0
  46. package/dist/commonjs/crypto.js.map +1 -0
  47. package/dist/commonjs/index.d.ts +18 -0
  48. package/dist/commonjs/index.d.ts.map +1 -0
  49. package/dist/commonjs/index.js +61 -0
  50. package/dist/commonjs/index.js.map +1 -0
  51. package/dist/commonjs/migrationUtils.d.ts +4 -0
  52. package/dist/commonjs/migrationUtils.d.ts.map +1 -0
  53. package/dist/commonjs/migrationUtils.js +52 -0
  54. package/dist/commonjs/migrationUtils.js.map +1 -0
  55. package/dist/commonjs/migrations.d.ts +99 -0
  56. package/dist/commonjs/migrations.d.ts.map +1 -0
  57. package/dist/commonjs/migrations.js +597 -0
  58. package/dist/commonjs/migrations.js.map +1 -0
  59. package/dist/commonjs/oauth.d.ts +98 -0
  60. package/dist/commonjs/oauth.d.ts.map +1 -0
  61. package/dist/commonjs/oauth.js +277 -0
  62. package/dist/commonjs/oauth.js.map +1 -0
  63. package/dist/commonjs/oauthCommon.d.ts +12 -0
  64. package/dist/commonjs/oauthCommon.d.ts.map +1 -0
  65. package/dist/commonjs/oauthCommon.js +26 -0
  66. package/dist/commonjs/oauthCommon.js.map +1 -0
  67. package/dist/commonjs/package.json +3 -0
  68. package/dist/commonjs/perms.d.ts +3 -0
  69. package/dist/commonjs/perms.d.ts.map +1 -0
  70. package/dist/commonjs/perms.js +66 -0
  71. package/dist/commonjs/perms.js.map +1 -0
  72. package/dist/commonjs/relationships.d.ts +7 -0
  73. package/dist/commonjs/relationships.d.ts.map +1 -0
  74. package/dist/commonjs/relationships.js +46 -0
  75. package/dist/commonjs/relationships.js.map +1 -0
  76. package/dist/commonjs/schema.d.ts +161 -0
  77. package/dist/commonjs/schema.d.ts.map +1 -0
  78. package/dist/commonjs/schema.js +174 -0
  79. package/dist/commonjs/schema.js.map +1 -0
  80. package/dist/commonjs/serverOAuth.d.ts +25 -0
  81. package/dist/commonjs/serverOAuth.d.ts.map +1 -0
  82. package/dist/commonjs/serverOAuth.js +72 -0
  83. package/dist/commonjs/serverOAuth.js.map +1 -0
  84. package/dist/commonjs/typescript-schema.d.ts +17 -0
  85. package/dist/commonjs/typescript-schema.d.ts.map +1 -0
  86. package/dist/commonjs/typescript-schema.js +314 -0
  87. package/dist/commonjs/typescript-schema.js.map +1 -0
  88. package/dist/commonjs/util.d.ts +13 -0
  89. package/dist/commonjs/util.d.ts.map +1 -0
  90. package/dist/commonjs/util.js +55 -0
  91. package/dist/commonjs/util.js.map +1 -0
  92. package/dist/commonjs/version.d.ts +3 -0
  93. package/dist/commonjs/version.d.ts.map +1 -0
  94. package/dist/commonjs/version.js +5 -0
  95. package/dist/commonjs/version.js.map +1 -0
  96. package/dist/esm/ProgressPromise.d.ts +18 -0
  97. package/dist/esm/ProgressPromise.d.ts.map +1 -0
  98. package/dist/esm/ProgressPromise.js +73 -0
  99. package/dist/esm/ProgressPromise.js.map +1 -0
  100. package/dist/esm/api.d.ts +480 -0
  101. package/dist/esm/api.d.ts.map +1 -0
  102. package/dist/esm/api.js +1121 -0
  103. package/dist/esm/api.js.map +1 -0
  104. package/dist/esm/backupDownload.d.ts +89 -0
  105. package/dist/esm/backupDownload.d.ts.map +1 -0
  106. package/dist/esm/backupDownload.js +354 -0
  107. package/dist/esm/backupDownload.js.map +1 -0
  108. package/dist/esm/backups.d.ts +146 -0
  109. package/dist/esm/backups.d.ts.map +1 -0
  110. package/dist/esm/backups.js +237 -0
  111. package/dist/esm/backups.js.map +1 -0
  112. package/dist/esm/clerk.d.ts +2 -0
  113. package/dist/esm/clerk.d.ts.map +1 -0
  114. package/dist/esm/clerk.js +26 -0
  115. package/dist/esm/clerk.js.map +1 -0
  116. package/dist/esm/consts.d.ts +11 -0
  117. package/dist/esm/consts.d.ts.map +1 -0
  118. package/dist/esm/consts.js +13 -0
  119. package/dist/esm/consts.js.map +1 -0
  120. package/dist/esm/crypto.d.ts +4 -0
  121. package/dist/esm/crypto.d.ts.map +1 -0
  122. package/dist/esm/crypto.js +21 -0
  123. package/dist/esm/crypto.js.map +1 -0
  124. package/dist/esm/index.d.ts +18 -0
  125. package/dist/esm/index.d.ts.map +1 -0
  126. package/dist/esm/index.js +17 -0
  127. package/dist/esm/index.js.map +1 -0
  128. package/dist/esm/migrationUtils.d.ts +4 -0
  129. package/dist/esm/migrationUtils.d.ts.map +1 -0
  130. package/dist/esm/migrationUtils.js +47 -0
  131. package/dist/esm/migrationUtils.js.map +1 -0
  132. package/dist/esm/migrations.d.ts +99 -0
  133. package/dist/esm/migrations.d.ts.map +1 -0
  134. package/dist/esm/migrations.js +588 -0
  135. package/dist/esm/migrations.js.map +1 -0
  136. package/dist/esm/oauth.d.ts +98 -0
  137. package/dist/esm/oauth.d.ts.map +1 -0
  138. package/dist/esm/oauth.js +268 -0
  139. package/dist/esm/oauth.js.map +1 -0
  140. package/dist/esm/oauthCommon.d.ts +12 -0
  141. package/dist/esm/oauthCommon.d.ts.map +1 -0
  142. package/dist/esm/oauthCommon.js +22 -0
  143. package/dist/esm/oauthCommon.js.map +1 -0
  144. package/dist/esm/package.json +3 -0
  145. package/dist/esm/perms.d.ts +3 -0
  146. package/dist/esm/perms.d.ts.map +1 -0
  147. package/dist/esm/perms.js +62 -0
  148. package/dist/esm/perms.js.map +1 -0
  149. package/dist/esm/relationships.d.ts +7 -0
  150. package/dist/esm/relationships.d.ts.map +1 -0
  151. package/dist/esm/relationships.js +43 -0
  152. package/dist/esm/relationships.js.map +1 -0
  153. package/dist/esm/schema.d.ts +161 -0
  154. package/dist/esm/schema.d.ts.map +1 -0
  155. package/dist/esm/schema.js +158 -0
  156. package/dist/esm/schema.js.map +1 -0
  157. package/dist/esm/serverOAuth.d.ts +25 -0
  158. package/dist/esm/serverOAuth.d.ts.map +1 -0
  159. package/dist/esm/serverOAuth.js +68 -0
  160. package/dist/esm/serverOAuth.js.map +1 -0
  161. package/dist/esm/typescript-schema.d.ts +17 -0
  162. package/dist/esm/typescript-schema.d.ts.map +1 -0
  163. package/dist/esm/typescript-schema.js +310 -0
  164. package/dist/esm/typescript-schema.js.map +1 -0
  165. package/dist/esm/util.d.ts +13 -0
  166. package/dist/esm/util.d.ts.map +1 -0
  167. package/dist/esm/util.js +46 -0
  168. package/dist/esm/util.js.map +1 -0
  169. package/dist/esm/version.d.ts +3 -0
  170. package/dist/esm/version.d.ts.map +1 -0
  171. package/dist/esm/version.js +3 -0
  172. package/dist/esm/version.js.map +1 -0
  173. package/dist/standalone/index.js +13747 -0
  174. package/dist/standalone/index.umd.cjs +72 -0
  175. package/package.json +69 -3
  176. package/src/ProgressPromise.ts +97 -0
  177. package/src/api.ts +1903 -0
  178. package/src/backupDownload.ts +519 -0
  179. package/src/backups.ts +342 -0
  180. package/src/clerk.ts +24 -0
  181. package/src/consts.ts +22 -0
  182. package/src/crypto.ts +28 -0
  183. package/src/index.ts +147 -0
  184. package/src/migrationUtils.ts +56 -0
  185. package/src/migrations.ts +920 -0
  186. package/src/oauth.ts +390 -0
  187. package/src/oauthCommon.ts +38 -0
  188. package/src/perms.ts +81 -0
  189. package/src/relationships.ts +57 -0
  190. package/src/schema.ts +497 -0
  191. package/src/serverOAuth.ts +119 -0
  192. package/src/typescript-schema.ts +439 -0
  193. package/src/util.ts +77 -0
  194. package/src/version.ts +3 -0
  195. package/tsconfig.dev.json +14 -0
  196. package/tsconfig.json +14 -0
  197. package/vite.config.ts +19 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverOAuth.js","sourceRoot":"","sources":["../../src/serverOAuth.ts"],"names":[],"mappings":";;AAGA,oDAsEC;AAED,oDA2CC;AAtHD,2CAAiD;AACjD,qDAAqD;AAE9C,KAAK,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C9B,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC;QAC/D,YAAY,EAAE,IAAI,CAAC,aAAa;QAChC,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS,EAAE,IAAI,CAAC,UAAU;KAC3B,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,oBAAoB,CAAC,EACzC,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,MAAM,EAAE,SAAS,GAMlB;IAMC,MAAM,MAAM,GAAG,IAAA,oBAAa,EAAC,SAAS,EAAE;QACtC,MAAM,EAAE,wBAAwB;KACjC,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,MAAM,uBAAuB,EAAE;QACxD,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,UAAU,EAAE,eAAe;YAC3B,aAAa,EAAE,YAAY;YAC3B,SAAS,EAAE,QAAQ;YACnB,aAAa,EAAE,YAAY;SAC5B,CAAC;KACH,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAK7B,CAAC;IAEF,OAAO;QACL,WAAW,EAAE,IAAI,CAAC,YAAY;QAC9B,SAAS,EAAE,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC;QAClD,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS,EAAE,IAAI,CAAC,UAAU;KAC3B,CAAC;AACJ,CAAC","sourcesContent":["import { requireApiURI } from '@sidekickdb/core';\nimport { InstantOAuthError } from './oauthCommon.ts';\n\nexport async function exchangeCodeForToken({\n code,\n clientId,\n clientSecret,\n redirectUri,\n apiURI: apiURIOpt,\n}: {\n code: string;\n clientId: string;\n clientSecret: string;\n redirectUri: string;\n apiURI?: string;\n}): Promise<{\n accessToken: string;\n refreshToken: string;\n expiresAt: Date;\n scopes: string;\n tokenType: 'Bearer';\n}> {\n const apiURI = requireApiURI(apiURIOpt, {\n target: 'exchangeCodeForToken()',\n });\n const res = await fetch(`${apiURI}/platform/oauth/token`, {\n method: 'POST',\n headers: { 'Content-type': 'application/json' },\n body: JSON.stringify({\n grant_type: 'authorization_code',\n code,\n redirect_uri: redirectUri,\n client_id: clientId,\n client_secret: clientSecret,\n }),\n });\n\n if (!res.ok) {\n const text = await res.text();\n let error;\n\n try {\n const json = JSON.parse(text);\n error = {\n error: json.error,\n errorDescription: json.error_description,\n message: `OAuth error: ${json.error || 'server_error'}`,\n };\n } catch (e) {\n error = {\n error: 'server_error',\n message: 'OAuth error: server_error',\n };\n }\n\n throw new InstantOAuthError(error);\n }\n\n const json = (await res.json()) as {\n access_token: string;\n refresh_token: string;\n expires_in: number;\n scopes: string;\n token_type: 'Bearer';\n };\n\n return {\n accessToken: json.access_token,\n expiresAt: new Date(Date.now() + (json.expires_in - 30) * 1000),\n refreshToken: json.refresh_token,\n scopes: json.scopes,\n tokenType: json.token_type,\n };\n}\n\nexport async function exchangeRefreshToken({\n clientId,\n clientSecret,\n refreshToken,\n apiURI: apiURIOpt,\n}: {\n clientId: string;\n clientSecret: string;\n refreshToken: string;\n apiURI?: string;\n}): Promise<{\n accessToken: string;\n expiresAt: Date;\n scopes: string;\n tokenType: 'Bearer';\n}> {\n const apiURI = requireApiURI(apiURIOpt, {\n target: 'exchangeRefreshToken()',\n });\n const res = await fetch(`${apiURI}/platform/oauth/token`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n grant_type: 'refresh_token',\n refresh_token: refreshToken,\n client_id: clientId,\n client_secret: clientSecret,\n }),\n });\n\n const json = (await res.json()) as {\n access_token: string;\n expires_in: number;\n scopes: string;\n token_type: 'Bearer';\n };\n\n return {\n accessToken: json.access_token,\n expiresAt: new Date((json.expires_in - 30) * 1000),\n scopes: json.scopes,\n tokenType: json.token_type,\n };\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import type { Node } from '@babel/types';
2
+ import { GenericSchemaDef } from './util.ts';
3
+ type JsonValue = string | number | boolean | null | JsonValue[] | {
4
+ [key: string]: JsonValue;
5
+ };
6
+ /**
7
+ * Converts a Babel AST node into a JavaScript object/value,
8
+ * suitable for JSON serialization.
9
+ * Throws errors for unsupported AST structures.
10
+ * @param {Node | null} node - The Babel AST node to convert.
11
+ * @returns {JsonValue | null} The JavaScript representation.
12
+ * @throws {Error} If the AST node or its structure is not convertible to JSON.
13
+ */
14
+ export declare function astToJson(node: Node | null): JsonValue | null;
15
+ export declare function schemaTypescriptFileToInstantSchema(content: string, sourceFilename?: string): GenericSchemaDef;
16
+ export {};
17
+ //# sourceMappingURL=typescript-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript-schema.d.ts","sourceRoot":"","sources":["../../src/typescript-schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,IAAI,EAQL,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7C,KAAK,SAAS,GACV,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEjC;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAqF7D;AA8SD,wBAAgB,mCAAmC,CACjD,OAAO,EAAE,MAAM,EACf,cAAc,GAAE,MAA4B,GAC3C,gBAAgB,CAclB"}
@@ -0,0 +1,314 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.astToJson = astToJson;
4
+ exports.schemaTypescriptFileToInstantSchema = schemaTypescriptFileToInstantSchema;
5
+ const parser_1 = require("@babel/parser");
6
+ const core_1 = require("@sidekickdb/core");
7
+ /**
8
+ * Converts a Babel AST node into a JavaScript object/value,
9
+ * suitable for JSON serialization.
10
+ * Throws errors for unsupported AST structures.
11
+ * @param {Node | null} node - The Babel AST node to convert.
12
+ * @returns {JsonValue | null} The JavaScript representation.
13
+ * @throws {Error} If the AST node or its structure is not convertible to JSON.
14
+ */
15
+ function astToJson(node) {
16
+ if (!node) {
17
+ return null;
18
+ }
19
+ switch (node.type) {
20
+ case 'ObjectExpression':
21
+ const objNode = node;
22
+ return objNode.properties.reduce((obj, prop) => {
23
+ if (prop.type === 'ObjectProperty') {
24
+ const objectProperty = prop;
25
+ let key;
26
+ if (objectProperty.key.type === 'Identifier') {
27
+ key = objectProperty.key.name;
28
+ }
29
+ else if (objectProperty.key.type === 'StringLiteral' ||
30
+ objectProperty.key.type === 'NumericLiteral') {
31
+ key = objectProperty.key
32
+ .value;
33
+ }
34
+ else {
35
+ throw new Error(`Unsupported key type in ObjectProperty: ${objectProperty.key.type}`);
36
+ }
37
+ obj[key] = astToJson(objectProperty.value);
38
+ }
39
+ else if (prop.type !== 'SpreadElement' &&
40
+ prop.type !== 'ObjectMethod') {
41
+ throw new Error(
42
+ // @ts-expect-error: prop is `never` here
43
+ `Unsupported property type in ObjectExpression: ${prop.type}`);
44
+ }
45
+ return obj;
46
+ }, {});
47
+ case 'ArrayExpression':
48
+ const arrNode = node;
49
+ return arrNode.elements
50
+ .map((element) => {
51
+ if (element && element.type === 'SpreadElement') {
52
+ return undefined;
53
+ }
54
+ return astToJson(element);
55
+ })
56
+ .filter((value) => value !== undefined);
57
+ case 'ObjectProperty':
58
+ const objPropNode = node;
59
+ let objectPropertyKey;
60
+ if (objPropNode.key.type === 'Identifier') {
61
+ objectPropertyKey = objPropNode.key.name;
62
+ }
63
+ else if (objPropNode.key.type === 'StringLiteral' ||
64
+ objPropNode.key.type === 'NumericLiteral') {
65
+ objectPropertyKey = objPropNode.key
66
+ .value;
67
+ }
68
+ else {
69
+ throw new Error(`Unsupported key type for standalone ObjectProperty: ${objPropNode.key.type}`);
70
+ }
71
+ const newObj = {};
72
+ newObj[objectPropertyKey] = astToJson(objPropNode.value);
73
+ return newObj;
74
+ case 'StringLiteral':
75
+ case 'NumericLiteral':
76
+ case 'BooleanLiteral':
77
+ return node.value;
78
+ case 'NullLiteral':
79
+ return null;
80
+ default:
81
+ throw new Error(`Unsupported AST node type for JSON conversion: ${node.type}`);
82
+ }
83
+ }
84
+ function keyName(property) {
85
+ switch (property.key.type) {
86
+ case 'Identifier':
87
+ return property.key.name;
88
+ case 'StringLiteral':
89
+ return property.key.value;
90
+ default:
91
+ throw new Error(`Could not extract entities, expected object key to be an \`Identifier\` or \`StringLiteral\`, got \`${property.key.type}\`.`);
92
+ }
93
+ }
94
+ function entityNodeToEntityDef(etype, node) {
95
+ const attrs = {};
96
+ for (const property of node.properties) {
97
+ if (property.type !== 'ObjectProperty') {
98
+ throw new Error(`Expected i.entity for \`${etype}\` to contain only \`ObjectProperty\`, got \`${property.type}\`.`);
99
+ }
100
+ const label = keyName(property);
101
+ const props = [];
102
+ if (property.value.type !== 'CallExpression') {
103
+ throw new Error(`Could not extract \`${etype}.${label}\`. Expected a call to \`i.string()\`, \`i.number()\`, etc. Got something else.`);
104
+ }
105
+ let next = property.value;
106
+ if (label === 'path') {
107
+ }
108
+ let attrDef = null;
109
+ while (next) {
110
+ if (next.callee.type !== 'MemberExpression' ||
111
+ next.callee.property.type !== 'Identifier' ||
112
+ !(next.callee.object.type === 'CallExpression' ||
113
+ (next.callee.object.type === 'Identifier' &&
114
+ next.callee.object.name === 'i'))) {
115
+ throw new Error(`Could not extract \`${etype}.${label}\`. Expected a call to \`i.string()\`, \`i.number()\`, etc. Got something else.`);
116
+ }
117
+ if (next.callee.object.type === 'CallExpression') {
118
+ props.push(next.callee.property.name);
119
+ next = next.callee.object;
120
+ }
121
+ else {
122
+ switch (next.callee.property.name) {
123
+ case 'string': {
124
+ attrDef = core_1.i.string();
125
+ break;
126
+ }
127
+ case 'number': {
128
+ attrDef = core_1.i.number();
129
+ break;
130
+ }
131
+ case 'boolean': {
132
+ attrDef = core_1.i.boolean();
133
+ break;
134
+ }
135
+ case 'date': {
136
+ attrDef = core_1.i.date();
137
+ break;
138
+ }
139
+ case 'json': {
140
+ attrDef = core_1.i.json();
141
+ break;
142
+ }
143
+ case 'any': {
144
+ attrDef = core_1.i.any();
145
+ break;
146
+ }
147
+ }
148
+ next = null;
149
+ }
150
+ }
151
+ if (!attrDef) {
152
+ throw new Error(`Could not extract \`${etype}.${label}\`. Found no call to \`i.string()\`, \`i.number()\`, etc.`);
153
+ }
154
+ for (const prop of props.reverse()) {
155
+ switch (prop) {
156
+ case 'indexed': {
157
+ attrDef = attrDef.indexed();
158
+ break;
159
+ }
160
+ case 'unique': {
161
+ attrDef = attrDef.unique();
162
+ break;
163
+ }
164
+ case 'optional': {
165
+ attrDef = attrDef.optional();
166
+ break;
167
+ }
168
+ case 'clientRequired': {
169
+ attrDef = attrDef.clientRequired();
170
+ break;
171
+ }
172
+ default: {
173
+ throw new Error(`Could not extract \`${etype}.${label}\`. Found a call to \`${prop}()\` that is not recognized.`);
174
+ }
175
+ }
176
+ }
177
+ attrs[label] = attrDef;
178
+ }
179
+ return core_1.i.entity(attrs);
180
+ }
181
+ function entitiesNodeToEntitiesDef(node) {
182
+ const entities = {};
183
+ for (const property of node.properties) {
184
+ if (property.type !== 'ObjectProperty') {
185
+ throw new Error(`Expected entities to contain only \`ObjectProperty\`, got \`${property.type}\`.`);
186
+ }
187
+ const etype = keyName(property);
188
+ if (property.value.type !== 'CallExpression' ||
189
+ property.value.callee.type !== 'MemberExpression' ||
190
+ property.value.callee.object.type !== 'Identifier' ||
191
+ property.value.callee.object.name !== 'i' ||
192
+ property.value.arguments.length !== 1 ||
193
+ property.value.arguments[0].type !== 'ObjectExpression') {
194
+ throw new Error(`Could not extract entity \`${etype}\`. Expected a call to \`i.entity()\`, got something else.`);
195
+ }
196
+ entities[etype] = entityNodeToEntityDef(etype, property.value.arguments[0]);
197
+ }
198
+ return entities;
199
+ }
200
+ function roomNodeToRoomDef(roomName, node) {
201
+ let presence = null;
202
+ let topics = undefined;
203
+ for (const property of node.properties) {
204
+ if (property.type !== 'ObjectProperty') {
205
+ throw new Error(`Expected entities to contain only \`ObjectProperty\`, got \`${property.type}\`.`);
206
+ }
207
+ const propName = keyName(property);
208
+ switch (propName) {
209
+ case 'topics': {
210
+ if (property.value.type !== 'ObjectExpression') {
211
+ throw new Error(`Could not exxtract \`rooms.${roomName}.topics\`. Expected an object, got \`${property.value.type}\`.`);
212
+ }
213
+ topics = entitiesNodeToEntitiesDef(property.value);
214
+ break;
215
+ }
216
+ case 'presence': {
217
+ if (property.value.type !== 'CallExpression' ||
218
+ property.value.callee.type !== 'MemberExpression' ||
219
+ property.value.callee.object.type !== 'Identifier' ||
220
+ property.value.callee.object.name !== 'i' ||
221
+ property.value.arguments.length !== 1 ||
222
+ property.value.arguments[0].type !== 'ObjectExpression') {
223
+ throw new Error(`Could not extract \`rooms.${roomName}.presence\`. Expected a call to \`i.entity()\`, got something else.`);
224
+ }
225
+ presence = entityNodeToEntityDef(roomName, property.value.arguments[0]);
226
+ break;
227
+ }
228
+ default: {
229
+ throw new Error(`Could not extract \`rooms.${roomName}\`. Unexpected property \`${propName}\`.`);
230
+ }
231
+ }
232
+ }
233
+ if (!presence) {
234
+ throw new Error(`Could not extract room ${roomName}, \`presence\` key was missing from room definition.`);
235
+ }
236
+ return { presence, topics };
237
+ }
238
+ function roomsNodeToRoomsDef(node) {
239
+ const rooms = {};
240
+ for (const property of node.properties) {
241
+ if (property.type !== 'ObjectProperty') {
242
+ throw new Error(`Expected entities to contain only \`ObjectProperty\`, got \`${property.type}\`.`);
243
+ }
244
+ const roomName = keyName(property);
245
+ if (property.value.type !== 'ObjectExpression') {
246
+ throw new Error(`Could not extract room \`${roomName}\`. Expected an object with topics and presence keys, got \`${property.value.type}\`.`);
247
+ }
248
+ rooms[roomName] = roomNodeToRoomDef(roomName, property.value);
249
+ }
250
+ return rooms;
251
+ }
252
+ function astToSchemaDef(ast) {
253
+ let entities = null;
254
+ let links = {};
255
+ let rooms = {};
256
+ for (const n of ast.program.body) {
257
+ if (n.type !== 'VariableDeclaration' ||
258
+ n.declarations.length !== 1 ||
259
+ n.declarations[0].id.type !== 'Identifier' ||
260
+ n.declarations[0].id.name !== '_schema') {
261
+ continue;
262
+ }
263
+ const node = n.declarations[0];
264
+ if (!node.init ||
265
+ node.init.type !== 'CallExpression' ||
266
+ node.init.callee.type !== 'MemberExpression' ||
267
+ node.init.callee.object.type !== 'Identifier' ||
268
+ node.init.callee.object.name !== 'i' ||
269
+ node.init.arguments.length !== 1 ||
270
+ node.init.arguments[0].type !== 'ObjectExpression') {
271
+ throw new Error(`Could not extract schema. Expected a call to \`i.schema()\`, got something else.`);
272
+ }
273
+ for (const property of node.init.arguments[0].properties) {
274
+ if (property.type !== 'ObjectProperty') {
275
+ throw new Error(`Could not extra schema property, expected an \`ObjectProperty\`, got \`${property.type}\'.`);
276
+ }
277
+ const section = keyName(property);
278
+ if (property.value.type !== 'ObjectExpression') {
279
+ throw new Error(`Failed to extract ${section}, expected an \`ObjectExpression\`, got \`${property.value.type}\`.`);
280
+ }
281
+ switch (keyName(property)) {
282
+ case 'entities': {
283
+ entities = entitiesNodeToEntitiesDef(property.value);
284
+ break;
285
+ }
286
+ case 'links': {
287
+ links = astToJson(property.value) || {};
288
+ break;
289
+ }
290
+ case 'rooms': {
291
+ rooms = roomsNodeToRoomsDef(property.value);
292
+ break;
293
+ }
294
+ }
295
+ }
296
+ }
297
+ if (!entities) {
298
+ throw new Error('Could not extract schema, did not find any entities.');
299
+ }
300
+ return core_1.i.schema({ entities, links, rooms });
301
+ }
302
+ function schemaTypescriptFileToInstantSchema(content, sourceFilename = 'instant.schema.ts') {
303
+ const ast = (0, parser_1.parse)(content, {
304
+ sourceFilename,
305
+ sourceType: 'module',
306
+ errorRecovery: false,
307
+ plugins: ['typescript'],
308
+ });
309
+ if (ast.errors?.length) {
310
+ throw new Error(`Could not parse schema file. ${ast.errors[0].reasonCode}.`);
311
+ }
312
+ return astToSchemaDef(ast);
313
+ }
314
+ //# sourceMappingURL=typescript-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript-schema.js","sourceRoot":"","sources":["../../src/typescript-schema.ts"],"names":[],"mappings":";;AAkCA,8BAqFC;AA8SD,kFAiBC;AAtbD,0CAAmE;AAgBnE,2CAA6D;AAU7D;;;;;;;GAOG;AACH,SAAgB,SAAS,CAAC,IAAiB;IACzC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,kBAAkB;YACrB,MAAM,OAAO,GAAG,IAAwB,CAAC;YACzC,OAAO,OAAO,CAAC,UAAU,CAAC,MAAM,CAC9B,CAAC,GAAiC,EAAE,IAAI,EAAE,EAAE;gBAC1C,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;oBACnC,MAAM,cAAc,GAAG,IAAsB,CAAC;oBAC9C,IAAI,GAAoB,CAAC;oBACzB,IAAI,cAAc,CAAC,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;wBAC7C,GAAG,GAAI,cAAc,CAAC,GAAkB,CAAC,IAAI,CAAC;oBAChD,CAAC;yBAAM,IACL,cAAc,CAAC,GAAG,CAAC,IAAI,KAAK,eAAe;wBAC3C,cAAc,CAAC,GAAG,CAAC,IAAI,KAAK,gBAAgB,EAC5C,CAAC;wBACD,GAAG,GAAI,cAAc,CAAC,GAAsC;6BACzD,KAAK,CAAC;oBACX,CAAC;yBAAM,CAAC;wBACN,MAAM,IAAI,KAAK,CACb,2CAA2C,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,CACrE,CAAC;oBACJ,CAAC;oBACD,GAAG,CAA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C,UAAU,GAAG,CAC5D,CAAC;IACJ,CAAC;IAED,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import { parse, type ParseResult, type File } from '@babel/parser';\nimport type {\n CallExpression,\n ObjectExpression,\n ObjectProperty,\n Node,\n Expression,\n Identifier,\n StringLiteral,\n NumericLiteral,\n ArrayExpression,\n SpreadElement,\n BooleanLiteral,\n} from '@babel/types';\n\nimport { GenericSchemaDef } from './util.ts';\nimport { AttrsDefs, DataAttrDef, i } from '@sidekickdb/core';\n\ntype JsonValue =\n | string\n | number\n | boolean\n | null\n | JsonValue[]\n | { [key: string]: JsonValue };\n\n/**\n * Converts a Babel AST node into a JavaScript object/value,\n * suitable for JSON serialization.\n * Throws errors for unsupported AST structures.\n * @param {Node | null} node - The Babel AST node to convert.\n * @returns {JsonValue | null} The JavaScript representation.\n * @throws {Error} If the AST node or its structure is not convertible to JSON.\n */\nexport function astToJson(node: Node | null): JsonValue | null {\n if (!node) {\n return null;\n }\n\n switch (node.type) {\n case 'ObjectExpression':\n const objNode = node as ObjectExpression;\n return objNode.properties.reduce(\n (obj: { [key: string]: JsonValue }, prop) => {\n if (prop.type === 'ObjectProperty') {\n const objectProperty = prop as ObjectProperty;\n let key: string | number;\n if (objectProperty.key.type === 'Identifier') {\n key = (objectProperty.key as Identifier).name;\n } else if (\n objectProperty.key.type === 'StringLiteral' ||\n objectProperty.key.type === 'NumericLiteral'\n ) {\n key = (objectProperty.key as StringLiteral | NumericLiteral)\n .value;\n } else {\n throw new Error(\n `Unsupported key type in ObjectProperty: ${objectProperty.key.type}`,\n );\n }\n obj[key] = astToJson(objectProperty.value);\n } else if (\n prop.type !== 'SpreadElement' &&\n prop.type !== 'ObjectMethod'\n ) {\n throw new Error(\n // @ts-expect-error: prop is `never` here\n `Unsupported property type in ObjectExpression: ${prop.type}`,\n );\n }\n return obj;\n },\n {},\n );\n\n case 'ArrayExpression':\n const arrNode = node as ArrayExpression;\n return arrNode.elements\n .map((element) => {\n if (element && element.type === 'SpreadElement') {\n return undefined;\n }\n return astToJson(element as Expression | SpreadElement | null);\n })\n .filter((value) => value !== undefined) as JsonValue[];\n\n case 'ObjectProperty':\n const objPropNode = node as ObjectProperty;\n let objectPropertyKey: string | number;\n if (objPropNode.key.type === 'Identifier') {\n objectPropertyKey = (objPropNode.key as Identifier).name;\n } else if (\n objPropNode.key.type === 'StringLiteral' ||\n objPropNode.key.type === 'NumericLiteral'\n ) {\n objectPropertyKey = (objPropNode.key as StringLiteral | NumericLiteral)\n .value;\n } else {\n throw new Error(\n `Unsupported key type for standalone ObjectProperty: ${objPropNode.key.type}`,\n );\n }\n const newObj: { [key: string]: JsonValue } = {};\n newObj[objectPropertyKey] = astToJson(objPropNode.value);\n return newObj;\n\n case 'StringLiteral':\n case 'NumericLiteral':\n case 'BooleanLiteral':\n return (node as StringLiteral | NumericLiteral | BooleanLiteral).value;\n\n case 'NullLiteral':\n return null;\n\n default:\n throw new Error(\n `Unsupported AST node type for JSON conversion: ${node.type}`,\n );\n }\n}\n\nfunction keyName(property: ObjectProperty): string {\n switch (property.key.type) {\n case 'Identifier':\n return property.key.name;\n case 'StringLiteral':\n return property.key.value;\n default:\n throw new Error(\n `Could not extract entities, expected object key to be an \\`Identifier\\` or \\`StringLiteral\\`, got \\`${property.key.type}\\`.`,\n );\n }\n}\n\nfunction entityNodeToEntityDef(\n etype: string,\n node: ObjectExpression,\n): GenericSchemaDef['entities'][string] {\n const attrs: AttrsDefs = {};\n for (const property of node.properties) {\n if (property.type !== 'ObjectProperty') {\n throw new Error(\n `Expected i.entity for \\`${etype}\\` to contain only \\`ObjectProperty\\`, got \\`${property.type}\\`.`,\n );\n }\n const label = keyName(property);\n\n const props = [];\n\n if (property.value.type !== 'CallExpression') {\n throw new Error(\n `Could not extract \\`${etype}.${label}\\`. Expected a call to \\`i.string()\\`, \\`i.number()\\`, etc. Got something else.`,\n );\n }\n let next: CallExpression | null = property.value;\n if (label === 'path') {\n }\n let attrDef: DataAttrDef<string, boolean, boolean> | null = null;\n while (next) {\n if (\n next.callee.type !== 'MemberExpression' ||\n next.callee.property.type !== 'Identifier' ||\n !(\n next.callee.object.type === 'CallExpression' ||\n (next.callee.object.type === 'Identifier' &&\n next.callee.object.name === 'i')\n )\n ) {\n throw new Error(\n `Could not extract \\`${etype}.${label}\\`. Expected a call to \\`i.string()\\`, \\`i.number()\\`, etc. Got something else.`,\n );\n }\n\n if (next.callee.object.type === 'CallExpression') {\n props.push(next.callee.property.name);\n next = next.callee.object;\n } else {\n switch (next.callee.property.name) {\n case 'string': {\n attrDef = i.string();\n break;\n }\n case 'number': {\n attrDef = i.number();\n break;\n }\n case 'boolean': {\n attrDef = i.boolean();\n break;\n }\n case 'date': {\n attrDef = i.date();\n break;\n }\n case 'json': {\n attrDef = i.json();\n break;\n }\n case 'any': {\n attrDef = i.any();\n break;\n }\n }\n next = null;\n }\n }\n\n if (!attrDef) {\n throw new Error(\n `Could not extract \\`${etype}.${label}\\`. Found no call to \\`i.string()\\`, \\`i.number()\\`, etc.`,\n );\n }\n\n for (const prop of props.reverse()) {\n switch (prop) {\n case 'indexed': {\n attrDef = attrDef.indexed();\n break;\n }\n case 'unique': {\n attrDef = attrDef.unique();\n break;\n }\n case 'optional': {\n attrDef = attrDef.optional();\n break;\n }\n case 'clientRequired': {\n attrDef = attrDef.clientRequired();\n break;\n }\n default: {\n throw new Error(\n `Could not extract \\`${etype}.${label}\\`. Found a call to \\`${prop}()\\` that is not recognized.`,\n );\n }\n }\n }\n\n attrs[label] = attrDef;\n }\n\n return i.entity(attrs);\n}\n\nfunction entitiesNodeToEntitiesDef(\n node: ObjectExpression,\n): GenericSchemaDef['entities'] {\n const entities: GenericSchemaDef['entities'] = {};\n for (const property of node.properties) {\n if (property.type !== 'ObjectProperty') {\n throw new Error(\n `Expected entities to contain only \\`ObjectProperty\\`, got \\`${property.type}\\`.`,\n );\n }\n const etype = keyName(property);\n if (\n property.value.type !== 'CallExpression' ||\n property.value.callee.type !== 'MemberExpression' ||\n property.value.callee.object.type !== 'Identifier' ||\n property.value.callee.object.name !== 'i' ||\n property.value.arguments.length !== 1 ||\n property.value.arguments[0].type !== 'ObjectExpression'\n ) {\n throw new Error(\n `Could not extract entity \\`${etype}\\`. Expected a call to \\`i.entity()\\`, got something else.`,\n );\n }\n entities[etype] = entityNodeToEntityDef(etype, property.value.arguments[0]);\n }\n\n return entities;\n}\n\nfunction roomNodeToRoomDef(\n roomName: string,\n node: ObjectExpression,\n): GenericSchemaDef['rooms'][string] {\n let presence: GenericSchemaDef['rooms'][string]['presence'] | null = null;\n let topics: GenericSchemaDef['rooms'][string]['topics'] | undefined =\n undefined;\n for (const property of node.properties) {\n if (property.type !== 'ObjectProperty') {\n throw new Error(\n `Expected entities to contain only \\`ObjectProperty\\`, got \\`${property.type}\\`.`,\n );\n }\n const propName = keyName(property);\n switch (propName) {\n case 'topics': {\n if (property.value.type !== 'ObjectExpression') {\n throw new Error(\n `Could not exxtract \\`rooms.${roomName}.topics\\`. Expected an object, got \\`${property.value.type}\\`.`,\n );\n }\n topics = entitiesNodeToEntitiesDef(property.value);\n break;\n }\n case 'presence': {\n if (\n property.value.type !== 'CallExpression' ||\n property.value.callee.type !== 'MemberExpression' ||\n property.value.callee.object.type !== 'Identifier' ||\n property.value.callee.object.name !== 'i' ||\n property.value.arguments.length !== 1 ||\n property.value.arguments[0].type !== 'ObjectExpression'\n ) {\n throw new Error(\n `Could not extract \\`rooms.${roomName}.presence\\`. Expected a call to \\`i.entity()\\`, got something else.`,\n );\n }\n presence = entityNodeToEntityDef(roomName, property.value.arguments[0]);\n break;\n }\n default: {\n throw new Error(\n `Could not extract \\`rooms.${roomName}\\`. Unexpected property \\`${propName}\\`.`,\n );\n }\n }\n }\n if (!presence) {\n throw new Error(\n `Could not extract room ${roomName}, \\`presence\\` key was missing from room definition.`,\n );\n }\n return { presence, topics };\n}\n\nfunction roomsNodeToRoomsDef(\n node: ObjectExpression,\n): GenericSchemaDef['rooms'] {\n const rooms: GenericSchemaDef['rooms'] = {};\n for (const property of node.properties) {\n if (property.type !== 'ObjectProperty') {\n throw new Error(\n `Expected entities to contain only \\`ObjectProperty\\`, got \\`${property.type}\\`.`,\n );\n }\n\n const roomName = keyName(property);\n\n if (property.value.type !== 'ObjectExpression') {\n throw new Error(\n `Could not extract room \\`${roomName}\\`. Expected an object with topics and presence keys, got \\`${property.value.type}\\`.`,\n );\n }\n\n rooms[roomName] = roomNodeToRoomDef(roomName, property.value);\n }\n\n return rooms;\n}\n\nfunction astToSchemaDef(ast: ParseResult<File>): GenericSchemaDef {\n let entities: GenericSchemaDef['entities'] | null = null;\n let links = {};\n let rooms = {};\n\n for (const n of ast.program.body) {\n if (\n n.type !== 'VariableDeclaration' ||\n n.declarations.length !== 1 ||\n n.declarations[0].id.type !== 'Identifier' ||\n n.declarations[0].id.name !== '_schema'\n ) {\n continue;\n }\n\n const node = n.declarations[0];\n\n if (\n !node.init ||\n node.init.type !== 'CallExpression' ||\n node.init.callee.type !== 'MemberExpression' ||\n node.init.callee.object.type !== 'Identifier' ||\n node.init.callee.object.name !== 'i' ||\n node.init.arguments.length !== 1 ||\n node.init.arguments[0].type !== 'ObjectExpression'\n ) {\n throw new Error(\n `Could not extract schema. Expected a call to \\`i.schema()\\`, got something else.`,\n );\n }\n\n for (const property of node.init.arguments[0].properties) {\n if (property.type !== 'ObjectProperty') {\n throw new Error(\n `Could not extra schema property, expected an \\`ObjectProperty\\`, got \\`${property.type}\\'.`,\n );\n }\n const section = keyName(property);\n if (property.value.type !== 'ObjectExpression') {\n throw new Error(\n `Failed to extract ${section}, expected an \\`ObjectExpression\\`, got \\`${property.value.type}\\`.`,\n );\n }\n switch (keyName(property)) {\n case 'entities': {\n entities = entitiesNodeToEntitiesDef(property.value);\n break;\n }\n case 'links': {\n links = astToJson(property.value) || {};\n break;\n }\n case 'rooms': {\n rooms = roomsNodeToRoomsDef(property.value);\n break;\n }\n }\n }\n }\n\n if (!entities) {\n throw new Error('Could not extract schema, did not find any entities.');\n }\n\n return i.schema({ entities, links, rooms });\n}\n\nexport function schemaTypescriptFileToInstantSchema(\n content: string,\n sourceFilename: string = 'instant.schema.ts',\n): GenericSchemaDef {\n const ast = parse(content, {\n sourceFilename,\n sourceType: 'module',\n errorRecovery: false,\n plugins: ['typescript'],\n });\n if (ast.errors?.length) {\n throw new Error(\n `Could not parse schema file. ${ast.errors[0].reasonCode}.`,\n );\n }\n\n return astToSchemaDef(ast);\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { AttrsDefs, CardinalityKind, EntityDef, InstantDBAttr, InstantDBCheckedDataType, InstantDBInferredType, InstantSchemaDef, LinksDef, RoomsDef } from '@sidekickdb/core';
2
+ export declare function sortedEntries<T>(o: Record<string, T>): [string, T][];
3
+ export declare function capitalizeFirstLetter(string: string): string;
4
+ export declare const rels: Record<string, CardinalityKind[]>;
5
+ export declare function indentLines(s: string, n?: number): string;
6
+ export declare function joinWithTrailingSep(arr: string[], sep: string, trailingSep?: string): string;
7
+ export declare function deriveClientType(attr: InstantDBAttr): {
8
+ type: InstantDBCheckedDataType | InstantDBInferredType | 'any';
9
+ origin: 'checked' | 'inferred' | 'unknown';
10
+ };
11
+ export declare function formatKey(key: string): string;
12
+ export type GenericSchemaDef = InstantSchemaDef<Record<string, EntityDef<AttrsDefs, any, any>>, LinksDef<Record<string, EntityDef<AttrsDefs, any, any>>>, RoomsDef>;
13
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,eAAe,EACf,SAAS,EACT,aAAa,EACb,wBAAwB,EACxB,qBAAqB,EACrB,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACT,MAAM,kBAAkB,CAAC;AAE1B,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAEpE;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,EAAE,CAKlD,CAAC;AAEF,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,SAAI,UAS3C;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EAAE,EACb,GAAG,EAAE,MAAM,EACX,WAAW,GAAE,MAAY,GACxB,MAAM,CAMR;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,GAAG;IACrD,IAAI,EAAE,wBAAwB,GAAG,qBAAqB,GAAG,KAAK,CAAC;IAC/D,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;CAC5C,CAMA;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UASpC;AAED,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAC7C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,EAC9C,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EACxD,QAAQ,CACT,CAAC"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rels = void 0;
4
+ exports.sortedEntries = sortedEntries;
5
+ exports.capitalizeFirstLetter = capitalizeFirstLetter;
6
+ exports.indentLines = indentLines;
7
+ exports.joinWithTrailingSep = joinWithTrailingSep;
8
+ exports.deriveClientType = deriveClientType;
9
+ exports.formatKey = formatKey;
10
+ function sortedEntries(o) {
11
+ return Object.entries(o).sort(([a], [b]) => a.localeCompare(b));
12
+ }
13
+ function capitalizeFirstLetter(string) {
14
+ return string.charAt(0).toUpperCase() + string.slice(1);
15
+ }
16
+ exports.rels = {
17
+ 'many-false': ['many', 'many'],
18
+ 'one-true': ['one', 'one'],
19
+ 'many-true': ['many', 'one'],
20
+ 'one-false': ['one', 'many'],
21
+ };
22
+ function indentLines(s, n = 2) {
23
+ if (!s) {
24
+ return s;
25
+ }
26
+ const space = ' '.repeat(n);
27
+ return s
28
+ .split('\n')
29
+ .map((l) => `${space}${l}`)
30
+ .join('\n');
31
+ }
32
+ function joinWithTrailingSep(arr, sep, trailingSep = sep) {
33
+ const s = arr.join(sep);
34
+ if (arr.length) {
35
+ return s + trailingSep;
36
+ }
37
+ return s;
38
+ }
39
+ function deriveClientType(attr) {
40
+ if (attr['checked-data-type']) {
41
+ return { type: attr['checked-data-type'], origin: 'checked' };
42
+ }
43
+ return { type: 'any', origin: 'unknown' };
44
+ }
45
+ function formatKey(key) {
46
+ return `"${key}"`;
47
+ // It would be nice to generate unquoted keys, but we use JSON.stringify
48
+ // for some things so we can't be consistent with it unless we write our own
49
+ // stringify function. If we do, here's the code for formatting keys:
50
+ // if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)) {
51
+ // return key;
52
+ // }
53
+ // return `"${key}"`;
54
+ }
55
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":";;;AAYA,sCAEC;AAED,sDAEC;AASD,kCASC;AAED,kDAUC;AAED,4CASC;AAED,8BASC;AA1DD,SAAgB,aAAa,CAAI,CAAoB;IACnD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,SAAgB,qBAAqB,CAAC,MAAc;IAClD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EA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C,OAAO,IAAI,GAAG,GAAG,CAAC;IAClB,wEAAwE;IACxE,4EAA4E;IAC5E,qEAAqE;IACrE,gDAAgD;IAChD,gBAAgB;IAChB,IAAI;IACJ,qBAAqB;AACvB,CAAC","sourcesContent":["import {\n AttrsDefs,\n CardinalityKind,\n EntityDef,\n InstantDBAttr,\n InstantDBCheckedDataType,\n InstantDBInferredType,\n InstantSchemaDef,\n LinksDef,\n RoomsDef,\n} from '@sidekickdb/core';\n\nexport function sortedEntries<T>(o: Record<string, T>): [string, T][] {\n return Object.entries(o).sort(([a], [b]) => a.localeCompare(b));\n}\n\nexport function capitalizeFirstLetter(string: string): string {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\nexport const rels: Record<string, CardinalityKind[]> = {\n 'many-false': ['many', 'many'],\n 'one-true': ['one', 'one'],\n 'many-true': ['many', 'one'],\n 'one-false': ['one', 'many'],\n};\n\nexport function indentLines(s: string, n = 2) {\n if (!s) {\n return s;\n }\n const space = ' '.repeat(n);\n return s\n .split('\\n')\n .map((l) => `${space}${l}`)\n .join('\\n');\n}\n\nexport function joinWithTrailingSep(\n arr: string[],\n sep: string,\n trailingSep: string = sep,\n): string {\n const s = arr.join(sep);\n if (arr.length) {\n return s + trailingSep;\n }\n return s;\n}\n\nexport function deriveClientType(attr: InstantDBAttr): {\n type: InstantDBCheckedDataType | InstantDBInferredType | 'any';\n origin: 'checked' | 'inferred' | 'unknown';\n} {\n if (attr['checked-data-type']) {\n return { type: attr['checked-data-type'], origin: 'checked' };\n }\n\n return { type: 'any', origin: 'unknown' };\n}\n\nexport function formatKey(key: string) {\n return `\"${key}\"`;\n // It would be nice to generate unquoted keys, but we use JSON.stringify\n // for some things so we can't be consistent with it unless we write our own\n // stringify function. If we do, here's the code for formatting keys:\n // if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)) {\n // return key;\n // }\n // return `\"${key}\"`;\n}\n\nexport type GenericSchemaDef = InstantSchemaDef<\n Record<string, EntityDef<AttrsDefs, any, any>>,\n LinksDef<Record<string, EntityDef<AttrsDefs, any, any>>>,\n RoomsDef\n>;\n"]}
@@ -0,0 +1,3 @@
1
+ import { version } from '@sidekickdb/version';
2
+ export default version;
3
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,eAAe,OAAO,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const version_1 = require("@sidekickdb/version");
4
+ exports.default = version_1.version;
5
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;AAAA,iDAA8C;AAE9C,kBAAe,iBAAO,CAAC","sourcesContent":["import { version } from '@sidekickdb/version';\n\nexport default version;\n"]}
@@ -0,0 +1,18 @@
1
+ export type ProgressPromiseSubscription = {
2
+ unsubscribe: () => void;
3
+ };
4
+ export type ProgressPromiseObserver<StatusT, ResultT> = {
5
+ next?: (t: StatusT) => void;
6
+ error?: (error: Error) => void;
7
+ complete?: (t: ResultT) => void;
8
+ };
9
+ export type ProgressPromiseConstructor<StatusT, ResultT> = (progress: (status: StatusT) => void, resolve: (result: ResultT) => void, reject: (error: Error) => void) => void;
10
+ export declare class ProgressPromise<StatusT, ResultT> {
11
+ #private;
12
+ constructor(callbackFn: ProgressPromiseConstructor<StatusT, ResultT>);
13
+ subscribe(observer: ProgressPromiseObserver<StatusT, ResultT>): ProgressPromiseSubscription;
14
+ then(resolve: (result: ResultT) => void, reject: (error: Error) => void): void;
15
+ catch(cb: (error: Error) => void): void;
16
+ finally(cb: () => void): void;
17
+ }
18
+ //# sourceMappingURL=ProgressPromise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProgressPromise.d.ts","sourceRoot":"","sources":["../../src/ProgressPromise.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,2BAA2B,GAAG;IACxC,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,uBAAuB,CAAC,OAAO,EAAE,OAAO,IAAI;IACtD,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5B,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC/B,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,0BAA0B,CAAC,OAAO,EAAE,OAAO,IAAI,CACzD,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,EACnC,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,EAClC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,KAC3B,IAAI,CAAC;AAEV,qBAAa,eAAe,CAAC,OAAO,EAAE,OAAO;;gBAO/B,UAAU,EAAE,0BAA0B,CAAC,OAAO,EAAE,OAAO,CAAC;IAyCpE,SAAS,CACP,QAAQ,EAAE,uBAAuB,CAAC,OAAO,EAAE,OAAO,CAAC,GAClD,2BAA2B;IAmB9B,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI;IAIvE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI;IAIhC,OAAO,CAAC,EAAE,EAAE,MAAM,IAAI;CAGvB"}
@@ -0,0 +1,73 @@
1
+ export class ProgressPromise {
2
+ #observers = [];
3
+ #result = null;
4
+ constructor(callbackFn) {
5
+ callbackFn(this.#onNext, this.#onComplete, this.#onError);
6
+ }
7
+ #onNext = (status) => {
8
+ if (this.#result) {
9
+ return;
10
+ }
11
+ for (const observer of this.#observers) {
12
+ try {
13
+ observer.next && observer.next(status);
14
+ }
15
+ catch (_e) { }
16
+ }
17
+ };
18
+ #onError = (error) => {
19
+ if (this.#result) {
20
+ return;
21
+ }
22
+ this.#result = { type: 'error', error };
23
+ for (const observer of this.#observers) {
24
+ try {
25
+ observer.error && observer.error(error);
26
+ }
27
+ catch (_e) { }
28
+ }
29
+ this.#observers = [];
30
+ };
31
+ #onComplete = (result) => {
32
+ if (this.#result) {
33
+ return;
34
+ }
35
+ this.#result = { type: 'complete', result };
36
+ for (const observer of this.#observers) {
37
+ try {
38
+ observer.complete && observer.complete(result);
39
+ }
40
+ catch (_e) { }
41
+ }
42
+ this.#observers = [];
43
+ };
44
+ subscribe(observer) {
45
+ if (this.#result) {
46
+ const ret = { unsubscribe: () => null };
47
+ if (this.#result.type === 'error') {
48
+ observer.error && observer.error(this.#result.error);
49
+ return ret;
50
+ }
51
+ else if (this.#result.type === 'complete') {
52
+ observer.complete && observer.complete(this.#result.result);
53
+ return ret;
54
+ }
55
+ }
56
+ this.#observers.push(observer);
57
+ return {
58
+ unsubscribe: () => {
59
+ this.#observers = this.#observers.filter((o) => o !== observer);
60
+ },
61
+ };
62
+ }
63
+ then(resolve, reject) {
64
+ this.subscribe({ error: reject, complete: resolve });
65
+ }
66
+ catch(cb) {
67
+ this.subscribe({ error: cb });
68
+ }
69
+ finally(cb) {
70
+ this.subscribe({ error: () => cb(), complete: () => cb() });
71
+ }
72
+ }
73
+ //# sourceMappingURL=ProgressPromise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProgressPromise.js","sourceRoot":"","sources":["../../src/ProgressPromise.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO,eAAe;IAC1B,UAAU,GAAgD,EAAE,CAAC;IAC7D,OAAO,GAGqC,IAAI,CAAC;IAEjD,YAAY,UAAwD;QAClE,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,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AAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF","sourcesContent":["export type ProgressPromiseSubscription = {\n unsubscribe: () => void;\n};\n\nexport type ProgressPromiseObserver<StatusT, ResultT> = {\n next?: (t: StatusT) => void;\n error?: (error: Error) => void;\n complete?: (t: ResultT) => void;\n};\n\nexport type ProgressPromiseConstructor<StatusT, ResultT> = (\n progress: (status: StatusT) => void,\n resolve: (result: ResultT) => void,\n reject: (error: Error) => void,\n) => void;\n\nexport class ProgressPromise<StatusT, ResultT> {\n #observers: ProgressPromiseObserver<StatusT, ResultT>[] = [];\n #result:\n | null\n | { type: 'error'; error: Error }\n | { type: 'complete'; result: ResultT } = null;\n\n constructor(callbackFn: ProgressPromiseConstructor<StatusT, ResultT>) {\n callbackFn(this.#onNext, this.#onComplete, this.#onError);\n }\n\n #onNext = (status: StatusT) => {\n if (this.#result) {\n return;\n }\n for (const observer of this.#observers) {\n try {\n observer.next && observer.next(status);\n } catch (_e) {}\n }\n };\n\n #onError = (error: Error) => {\n if (this.#result) {\n return;\n }\n this.#result = { type: 'error', error };\n for (const observer of this.#observers) {\n try {\n observer.error && observer.error(error);\n } catch (_e) {}\n }\n this.#observers = [];\n };\n\n #onComplete = (result: ResultT) => {\n if (this.#result) {\n return;\n }\n this.#result = { type: 'complete', result };\n for (const observer of this.#observers) {\n try {\n observer.complete && observer.complete(result);\n } catch (_e) {}\n }\n this.#observers = [];\n };\n\n subscribe(\n observer: ProgressPromiseObserver<StatusT, ResultT>,\n ): ProgressPromiseSubscription {\n if (this.#result) {\n const ret = { unsubscribe: () => null };\n if (this.#result.type === 'error') {\n observer.error && observer.error(this.#result.error);\n return ret;\n } else if (this.#result.type === 'complete') {\n observer.complete && observer.complete(this.#result.result);\n return ret;\n }\n }\n this.#observers.push(observer);\n return {\n unsubscribe: () => {\n this.#observers = this.#observers.filter((o) => o !== observer);\n },\n };\n }\n\n then(resolve: (result: ResultT) => void, reject: (error: Error) => void) {\n this.subscribe({ error: reject, complete: resolve });\n }\n\n catch(cb: (error: Error) => void) {\n this.subscribe({ error: cb });\n }\n\n finally(cb: () => void) {\n this.subscribe({ error: () => cb(), complete: () => cb() });\n }\n}\n"]}