@sidekickdb/react 0.0.0 → 2.0.1

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 (134) 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/LICENSE.md +202 -0
  5. package/NOTICE +27 -0
  6. package/README.md +43 -2
  7. package/__example__/standalone.esm.html +32 -0
  8. package/__example__/standalone.umd.html +27 -0
  9. package/dist/commonjs/Cursors.d.ts +19 -0
  10. package/dist/commonjs/Cursors.d.ts.map +1 -0
  11. package/dist/commonjs/Cursors.js +107 -0
  12. package/dist/commonjs/Cursors.js.map +1 -0
  13. package/dist/commonjs/InstantReactWebDatabase.d.ts +7 -0
  14. package/dist/commonjs/InstantReactWebDatabase.d.ts.map +1 -0
  15. package/dist/commonjs/InstantReactWebDatabase.js +9 -0
  16. package/dist/commonjs/InstantReactWebDatabase.js.map +1 -0
  17. package/dist/commonjs/__types__/typeUtils.d.ts +20 -0
  18. package/dist/commonjs/__types__/typeUtils.d.ts.map +1 -0
  19. package/dist/commonjs/__types__/typeUtils.js +5 -0
  20. package/dist/commonjs/__types__/typeUtils.js.map +1 -0
  21. package/dist/commonjs/__types__/typesTests.d.ts +2 -0
  22. package/dist/commonjs/__types__/typesTests.d.ts.map +1 -0
  23. package/dist/commonjs/__types__/typesTests.js +57 -0
  24. package/dist/commonjs/__types__/typesTests.js.map +1 -0
  25. package/dist/commonjs/index.d.ts +7 -0
  26. package/dist/commonjs/index.d.ts.map +1 -0
  27. package/dist/commonjs/index.js +30 -0
  28. package/dist/commonjs/index.js.map +1 -0
  29. package/dist/commonjs/init.d.ts +41 -0
  30. package/dist/commonjs/init.d.ts.map +1 -0
  31. package/dist/commonjs/init.js +57 -0
  32. package/dist/commonjs/init.js.map +1 -0
  33. package/dist/commonjs/next-ssr/HydrationStreamProvider.d.ts +66 -0
  34. package/dist/commonjs/next-ssr/HydrationStreamProvider.d.ts.map +1 -0
  35. package/dist/commonjs/next-ssr/HydrationStreamProvider.js +134 -0
  36. package/dist/commonjs/next-ssr/HydrationStreamProvider.js.map +1 -0
  37. package/dist/commonjs/next-ssr/InstantNextDatabase.d.ts +12 -0
  38. package/dist/commonjs/next-ssr/InstantNextDatabase.d.ts.map +1 -0
  39. package/dist/commonjs/next-ssr/InstantNextDatabase.js +39 -0
  40. package/dist/commonjs/next-ssr/InstantNextDatabase.js.map +1 -0
  41. package/dist/commonjs/next-ssr/InstantSuspenseProvider.d.ts +25 -0
  42. package/dist/commonjs/next-ssr/InstantSuspenseProvider.d.ts.map +1 -0
  43. package/dist/commonjs/next-ssr/InstantSuspenseProvider.js +168 -0
  44. package/dist/commonjs/next-ssr/InstantSuspenseProvider.js.map +1 -0
  45. package/dist/commonjs/next-ssr/getUserFromInstantCookie.d.ts +10 -0
  46. package/dist/commonjs/next-ssr/getUserFromInstantCookie.d.ts.map +1 -0
  47. package/dist/commonjs/next-ssr/getUserFromInstantCookie.js +22 -0
  48. package/dist/commonjs/next-ssr/getUserFromInstantCookie.js.map +1 -0
  49. package/dist/commonjs/next-ssr/htmlescape.d.ts +3 -0
  50. package/dist/commonjs/next-ssr/htmlescape.d.ts.map +1 -0
  51. package/dist/commonjs/next-ssr/htmlescape.js +25 -0
  52. package/dist/commonjs/next-ssr/htmlescape.js.map +1 -0
  53. package/dist/commonjs/next-ssr/index.d.ts +30 -0
  54. package/dist/commonjs/next-ssr/index.d.ts.map +1 -0
  55. package/dist/commonjs/next-ssr/index.js +47 -0
  56. package/dist/commonjs/next-ssr/index.js.map +1 -0
  57. package/dist/commonjs/package.json +3 -0
  58. package/dist/commonjs/version.d.ts +3 -0
  59. package/dist/commonjs/version.d.ts.map +1 -0
  60. package/dist/commonjs/version.js +5 -0
  61. package/dist/commonjs/version.js.map +1 -0
  62. package/dist/esm/Cursors.d.ts +19 -0
  63. package/dist/esm/Cursors.d.ts.map +1 -0
  64. package/dist/esm/Cursors.js +104 -0
  65. package/dist/esm/Cursors.js.map +1 -0
  66. package/dist/esm/InstantReactWebDatabase.d.ts +7 -0
  67. package/dist/esm/InstantReactWebDatabase.d.ts.map +1 -0
  68. package/dist/esm/InstantReactWebDatabase.js +6 -0
  69. package/dist/esm/InstantReactWebDatabase.js.map +1 -0
  70. package/dist/esm/__types__/typeUtils.d.ts +20 -0
  71. package/dist/esm/__types__/typeUtils.d.ts.map +1 -0
  72. package/dist/esm/__types__/typeUtils.js +4 -0
  73. package/dist/esm/__types__/typeUtils.js.map +1 -0
  74. package/dist/esm/__types__/typesTests.d.ts +2 -0
  75. package/dist/esm/__types__/typesTests.d.ts.map +1 -0
  76. package/dist/esm/__types__/typesTests.js +55 -0
  77. package/dist/esm/__types__/typesTests.js.map +1 -0
  78. package/dist/esm/index.d.ts +7 -0
  79. package/dist/esm/index.d.ts.map +1 -0
  80. package/dist/esm/index.js +23 -0
  81. package/dist/esm/index.js.map +1 -0
  82. package/dist/esm/init.d.ts +41 -0
  83. package/dist/esm/init.d.ts.map +1 -0
  84. package/dist/esm/init.js +50 -0
  85. package/dist/esm/init.js.map +1 -0
  86. package/dist/esm/next-ssr/HydrationStreamProvider.d.ts +66 -0
  87. package/dist/esm/next-ssr/HydrationStreamProvider.d.ts.map +1 -0
  88. package/dist/esm/next-ssr/HydrationStreamProvider.js +97 -0
  89. package/dist/esm/next-ssr/HydrationStreamProvider.js.map +1 -0
  90. package/dist/esm/next-ssr/InstantNextDatabase.d.ts +12 -0
  91. package/dist/esm/next-ssr/InstantNextDatabase.d.ts.map +1 -0
  92. package/dist/esm/next-ssr/InstantNextDatabase.js +32 -0
  93. package/dist/esm/next-ssr/InstantNextDatabase.js.map +1 -0
  94. package/dist/esm/next-ssr/InstantSuspenseProvider.d.ts +25 -0
  95. package/dist/esm/next-ssr/InstantSuspenseProvider.d.ts.map +1 -0
  96. package/dist/esm/next-ssr/InstantSuspenseProvider.js +163 -0
  97. package/dist/esm/next-ssr/InstantSuspenseProvider.js.map +1 -0
  98. package/dist/esm/next-ssr/getUserFromInstantCookie.d.ts +10 -0
  99. package/dist/esm/next-ssr/getUserFromInstantCookie.d.ts.map +1 -0
  100. package/dist/esm/next-ssr/getUserFromInstantCookie.js +17 -0
  101. package/dist/esm/next-ssr/getUserFromInstantCookie.js.map +1 -0
  102. package/dist/esm/next-ssr/htmlescape.d.ts +3 -0
  103. package/dist/esm/next-ssr/htmlescape.d.ts.map +1 -0
  104. package/dist/esm/next-ssr/htmlescape.js +21 -0
  105. package/dist/esm/next-ssr/htmlescape.js.map +1 -0
  106. package/dist/esm/next-ssr/index.d.ts +30 -0
  107. package/dist/esm/next-ssr/index.d.ts.map +1 -0
  108. package/dist/esm/next-ssr/index.js +35 -0
  109. package/dist/esm/next-ssr/index.js.map +1 -0
  110. package/dist/esm/package.json +3 -0
  111. package/dist/esm/version.d.ts +3 -0
  112. package/dist/esm/version.d.ts.map +1 -0
  113. package/dist/esm/version.js +3 -0
  114. package/dist/esm/version.js.map +1 -0
  115. package/dist/standalone/index.js +9664 -0
  116. package/dist/standalone/index.umd.cjs +40 -0
  117. package/package.json +81 -3
  118. package/src/Cursors.tsx +208 -0
  119. package/src/InstantReactWebDatabase.ts +14 -0
  120. package/src/__types__/typeUtils.ts +39 -0
  121. package/src/__types__/typesTests.ts +90 -0
  122. package/src/index.ts +227 -0
  123. package/src/init.ts +67 -0
  124. package/src/next-ssr/HydrationStreamProvider.tsx +200 -0
  125. package/src/next-ssr/InstantNextDatabase.tsx +56 -0
  126. package/src/next-ssr/InstantSuspenseProvider.tsx +290 -0
  127. package/src/next-ssr/getUserFromInstantCookie.ts +23 -0
  128. package/src/next-ssr/htmlescape.ts +24 -0
  129. package/src/next-ssr/index.tsx +54 -0
  130. package/src/version.ts +3 -0
  131. package/tsconfig.dev.json +14 -0
  132. package/tsconfig.json +13 -0
  133. package/tsconfig.test.json +5 -0
  134. package/vite.config.ts +35 -0
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_ts_1 = require("../index.js");
4
+ const schema = index_ts_1.i.schema({
5
+ entities: {
6
+ tbl: index_ts_1.i.entity({
7
+ d: index_ts_1.i.date().indexed(),
8
+ dOptional: index_ts_1.i.date().optional(),
9
+ }),
10
+ },
11
+ });
12
+ function _testUseDatesTest() {
13
+ const db = (0, index_ts_1.init)({
14
+ schema,
15
+ appId: '123',
16
+ apiURI: 'https://sidekick.example.com',
17
+ useDateObjects: true,
18
+ });
19
+ const { data } = db.useQuery({ tbl: {} });
20
+ const item = data?.tbl[0];
21
+ if (item) {
22
+ }
23
+ }
24
+ function _testUseDatesFalseTest() {
25
+ const db = (0, index_ts_1.init)({
26
+ schema,
27
+ appId: '123',
28
+ apiURI: 'https://sidekick.example.com',
29
+ useDateObjects: false,
30
+ });
31
+ const { data } = db.useQuery({ tbl: {} });
32
+ const item = data?.tbl[0];
33
+ if (item) {
34
+ }
35
+ }
36
+ function _testUseDatesUndefinedTest() {
37
+ const db = (0, index_ts_1.init)({
38
+ schema,
39
+ appId: '123',
40
+ apiURI: 'https://sidekick.example.com',
41
+ });
42
+ const { data } = db.useQuery({ tbl: {} });
43
+ const item = data?.tbl[0];
44
+ if (item) {
45
+ }
46
+ }
47
+ function _testDataNoSchema() {
48
+ const db = (0, index_ts_1.init)({
49
+ appId: '123',
50
+ apiURI: 'https://sidekick.example.com',
51
+ });
52
+ const { data } = db.useQuery({ tbl: {} });
53
+ const item = data?.tbl[0];
54
+ if (item) {
55
+ }
56
+ }
57
+ //# sourceMappingURL=typesTests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typesTests.js","sourceRoot":"","sources":["../../../src/__types__/typesTests.ts"],"names":[],"mappings":";;AACA,0CAAsC;AAEtC,MAAM,MAAM,GAAG,YAAC,CAAC,MAAM,CAAC;IACtB,QAAQ,EAAE;QACR,GAAG,EAAE,YAAC,CAAC,MAAM,CAAC;YACZ,CAAC,EAAE,YAAC,CAAC,IAAI,EAAE,CAAC,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CAAC;AACH,CAAC;AAED,SAAS,iBAAiB;IACxB,MAAM,EAAE,GAAG,IAAA,eAAI,EAAC;QACd,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,8BAA8B;KACvC,CAAC,CAAC;IAEH,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,IAAI,EAAE,CAAC;IAGX,CAAC;AACH,CAAC","sourcesContent":["import type { Equal, Expect, IsAny, NotAny } from './typeUtils.ts';\nimport { i, init } from '../index.ts';\n\nconst schema = i.schema({\n entities: {\n tbl: i.entity({\n d: i.date().indexed(),\n dOptional: i.date().optional(),\n }),\n },\n});\n\nfunction _testUseDatesTest() {\n const db = init({\n schema,\n appId: '123',\n apiURI: 'https://sidekick.example.com',\n useDateObjects: true,\n });\n\n const { data } = db.useQuery({ tbl: {} });\n const item = data?.tbl[0];\n if (item) {\n type t = typeof item.d;\n type _cases = [Expect<NotAny<t>>, Expect<Equal<t, Date>>];\n\n type tOpt = typeof item.dOptional;\n type _cases_2 = [\n Expect<NotAny<tOpt>>,\n Expect<Equal<tOpt, Date | undefined>>,\n ];\n }\n}\n\nfunction _testUseDatesFalseTest() {\n const db = init({\n schema,\n appId: '123',\n apiURI: 'https://sidekick.example.com',\n useDateObjects: false,\n });\n\n const { data } = db.useQuery({ tbl: {} });\n const item = data?.tbl[0];\n if (item) {\n type t = typeof item.d;\n type _cases = [Expect<NotAny<t>>, Expect<Equal<t, string | number>>];\n\n type tOpt = typeof item.dOptional;\n type _cases_2 = [\n Expect<NotAny<tOpt>>,\n Expect<Equal<tOpt, string | number | undefined>>,\n ];\n }\n}\n\nfunction _testUseDatesUndefinedTest() {\n const db = init({\n schema,\n appId: '123',\n apiURI: 'https://sidekick.example.com',\n });\n\n const { data } = db.useQuery({ tbl: {} });\n const item = data?.tbl[0];\n if (item) {\n type t = typeof item.d;\n type _cases = [Expect<NotAny<t>>, Expect<Equal<t, string | number>>];\n\n type tOpt = typeof item.dOptional;\n type _cases_2 = [\n Expect<NotAny<tOpt>>,\n Expect<Equal<tOpt, string | number | undefined>>,\n ];\n }\n}\n\nfunction _testDataNoSchema() {\n const db = init({\n appId: '123',\n apiURI: 'https://sidekick.example.com',\n });\n\n const { data } = db.useQuery({ tbl: {} });\n const item = data?.tbl[0];\n if (item) {\n type t = typeof item.d;\n type _cases = [Expect<IsAny<t>>, Expect<Equal<typeof item.id, string>>];\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import { id, tx, lookup, i, InstantAPIError, SyncTableCallbackEventType, setInstantWarningsEnabled, type QueryResponse, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantObject, type InstantEntity, type InstantSchemaDatabase, type InstantUnknownSchemaDef, type IInstantDatabase, type User, type AuthState, type Query, type Config, type InstaQLParams, type ConnectionStatus, type AppStatusState, type ValidQuery, type PresencePeer, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type InstantConfig, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type InstaQLEntity, type InstaQLFields, type InstaQLResult, type InstaQLEntitySubquery, type RoomsOf, type RoomsDef, type PresenceOf, type TopicsOf, type TopicOf, type RoomHandle, type TransactionChunk, type InstantUnknownSchema, type InstantSchemaDef, type BackwardsCompatibleSchema, type InstantRules, type UpdateParams, type LinkParams, type CreateParams, type CheckMagicCodeParams, type CheckMagicCodeResponse, type ExchangeCodeForTokenParams, type SendMagicCodeParams, type SendMagicCodeResponse, type SignInWithIdTokenParams, type VerifyMagicCodeParams, type VerifyResponse, type FileOpts, type UploadFileResponse, type DeleteFileResponse, type CreateReadStreamOpts, type CreateWriteStreamOpts, type SyncTableCallback, type SyncTableCallbackEvent, type SyncTableInitialSyncBatch, type SyncTableInitialSyncComplete, type SyncTableSyncTransaction, type SyncTableLoadFromStorage, type SyncTableSetupError, StoreInterface, createInstantRouteHandler, type InstantRouteHandlerPayloadByType, type InstantRouteHandlerType, type InstantRouteHandlerBody, type StoreInterfaceStoreName, InstantWritableStream, InstantReadableStream, type Logger } from '@sidekickdb/core';
2
+ import { InstantReactAbstractDatabase } from '@sidekickdb/react-common';
3
+ import InstantReactWebDatabase from './InstantReactWebDatabase.ts';
4
+ import { init, init_experimental } from './init.ts';
5
+ import { Cursors } from './Cursors.tsx';
6
+ export { id, tx, lookup, init, init_experimental, InstantReactWebDatabase, Cursors, i, InstantAPIError, InstantReactAbstractDatabase, SyncTableCallbackEventType, setInstantWarningsEnabled, type Config, type InstantConfig, type InstantUnknownSchemaDef, type Query, type QueryResponse, type InstantObject, type User, type AuthState, type ConnectionStatus, type AppStatusState, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantEntity, type InstantSchemaDatabase, type IInstantDatabase, type InstaQLParams, type ValidQuery, type InstaQLFields, type PresencePeer, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type InstaQLEntity, type InstaQLResult, type InstaQLEntitySubquery, type RoomsOf, type RoomsDef, type TransactionChunk, type PresenceOf, type TopicsOf, type TopicOf, type RoomHandle, type InstantUnknownSchema, type InstantSchemaDef, type BackwardsCompatibleSchema, type InstantRules, type UpdateParams, type LinkParams, type CreateParams, type CheckMagicCodeParams, type CheckMagicCodeResponse, type ExchangeCodeForTokenParams, type SendMagicCodeParams, type SendMagicCodeResponse, type SignInWithIdTokenParams, type VerifyMagicCodeParams, type VerifyResponse, type FileOpts, type UploadFileResponse, type DeleteFileResponse, type CreateReadStreamOpts, type CreateWriteStreamOpts, type InstantWritableStream, type InstantReadableStream, StoreInterface, type StoreInterfaceStoreName, type SyncTableCallback, type SyncTableCallbackEvent, type SyncTableInitialSyncBatch, type SyncTableInitialSyncComplete, type SyncTableSyncTransaction, type SyncTableLoadFromStorage, type SyncTableSetupError, createInstantRouteHandler, type InstantRouteHandlerPayloadByType, type InstantRouteHandlerType, type InstantRouteHandlerBody, type Logger, };
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,EAAE,EACF,MAAM,EACN,CAAC,EAGD,eAAe,EAGf,0BAA0B,EAC1B,yBAAyB,EAGzB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,UAAU,EAGf,KAAK,YAAY,EAGjB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB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5B,KAAK,uBAAuB,EAG5B,KAAK,MAAM,GACZ,CAAC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createInstantRouteHandler = exports.StoreInterface = exports.setInstantWarningsEnabled = exports.SyncTableCallbackEventType = exports.InstantReactAbstractDatabase = exports.InstantAPIError = exports.i = exports.Cursors = exports.InstantReactWebDatabase = exports.init_experimental = exports.init = exports.lookup = exports.tx = exports.id = void 0;
7
+ const core_1 = require("@sidekickdb/core");
8
+ Object.defineProperty(exports, "id", { enumerable: true, get: function () { return core_1.id; } });
9
+ Object.defineProperty(exports, "tx", { enumerable: true, get: function () { return core_1.tx; } });
10
+ Object.defineProperty(exports, "lookup", { enumerable: true, get: function () { return core_1.lookup; } });
11
+ Object.defineProperty(exports, "i", { enumerable: true, get: function () { return core_1.i; } });
12
+ Object.defineProperty(exports, "InstantAPIError", { enumerable: true, get: function () { return
13
+ // error
14
+ core_1.InstantAPIError; } });
15
+ Object.defineProperty(exports, "SyncTableCallbackEventType", { enumerable: true, get: function () { return
16
+ // sync table enums
17
+ core_1.SyncTableCallbackEventType; } });
18
+ Object.defineProperty(exports, "setInstantWarningsEnabled", { enumerable: true, get: function () { return core_1.setInstantWarningsEnabled; } });
19
+ Object.defineProperty(exports, "StoreInterface", { enumerable: true, get: function () { return core_1.StoreInterface; } });
20
+ Object.defineProperty(exports, "createInstantRouteHandler", { enumerable: true, get: function () { return core_1.createInstantRouteHandler; } });
21
+ const react_common_1 = require("@sidekickdb/react-common");
22
+ Object.defineProperty(exports, "InstantReactAbstractDatabase", { enumerable: true, get: function () { return react_common_1.InstantReactAbstractDatabase; } });
23
+ const InstantReactWebDatabase_ts_1 = __importDefault(require("./InstantReactWebDatabase.js"));
24
+ exports.InstantReactWebDatabase = InstantReactWebDatabase_ts_1.default;
25
+ const init_ts_1 = require("./init.js");
26
+ Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_ts_1.init; } });
27
+ Object.defineProperty(exports, "init_experimental", { enumerable: true, get: function () { return init_ts_1.init_experimental; } });
28
+ const Cursors_tsx_1 = require("./Cursors.js");
29
+ Object.defineProperty(exports, "Cursors", { enumerable: true, get: function () { return Cursors_tsx_1.Cursors; } });
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAsG0B;AAQxB,mFA7GA,SAAE,OA6GA;AACF,mFA7GA,SAAE,OA6GA;AACF,uFA7GA,aAAM,OA6GA;AAKN,kFAjHA,QAAC,OAiHA;AAGD;IAlHA,QAAQ;IACR,sBAAe,OAiHA;AAMf;IArHA,mBAAmB;IACnB,iCAA0B,OAoHA;AAG1B,0GAtHA,gCAAyB,OAsHA;AA6EzB,+FAjHA,qBAAc,OAiHA;AAad,0GA7HA,gCAAyB,OA6HA;AAnH3B,2DAAwE;AAmBtE,6GAnBO,2CAA4B,OAmBP;AAlB9B,8FAAmE;AAUjE,kCAVK,oCAAuB,CAUL;AATzB,uCAAoD;AAOlD,qFAPO,cAAI,OAOP;AACJ,kGARa,2BAAiB,OAQb;AAPnB,8CAAwC;AAStC,wFATO,qBAAO,OASP","sourcesContent":["import {\n id,\n tx,\n lookup,\n i,\n\n // error\n InstantAPIError,\n\n // sync table enums\n SyncTableCallbackEventType,\n setInstantWarningsEnabled,\n\n // types\n type QueryResponse,\n type InstantQuery,\n type InstantQueryResult,\n type InstantSchema,\n type InstantObject,\n type InstantEntity,\n type InstantSchemaDatabase,\n type InstantUnknownSchemaDef,\n type IInstantDatabase,\n type User,\n type AuthState,\n type Query,\n type Config,\n type InstaQLParams,\n type ConnectionStatus,\n type AppStatusState,\n type ValidQuery,\n\n // presence types\n type PresencePeer,\n\n // schema types\n type AttrsDefs,\n type CardinalityKind,\n type DataAttrDef,\n type EntitiesDef,\n type EntitiesWithLinks,\n type EntityDef,\n type InstantGraph,\n type InstantConfig,\n type LinkAttrDef,\n type LinkDef,\n type LinksDef,\n type ResolveAttrs,\n type ValueTypes,\n type InstaQLEntity,\n type InstaQLFields,\n type InstaQLResult,\n type InstaQLEntitySubquery,\n type RoomsOf,\n type RoomsDef,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type RoomHandle,\n type TransactionChunk,\n type InstantUnknownSchema,\n type InstantSchemaDef,\n type BackwardsCompatibleSchema,\n type InstantRules,\n type UpdateParams,\n type LinkParams,\n type CreateParams,\n type CheckMagicCodeParams,\n type CheckMagicCodeResponse,\n type ExchangeCodeForTokenParams,\n type SendMagicCodeParams,\n type SendMagicCodeResponse,\n type SignInWithIdTokenParams,\n type VerifyMagicCodeParams,\n type VerifyResponse,\n\n // storage types\n type FileOpts,\n type UploadFileResponse,\n type DeleteFileResponse,\n\n // stream types\n type CreateReadStreamOpts,\n type CreateWriteStreamOpts,\n\n // sync table types\n type SyncTableCallback,\n type SyncTableCallbackEvent,\n type SyncTableInitialSyncBatch,\n type SyncTableInitialSyncComplete,\n type SyncTableSyncTransaction,\n type SyncTableLoadFromStorage,\n type SyncTableSetupError,\n StoreInterface,\n createInstantRouteHandler,\n type InstantRouteHandlerPayloadByType,\n type InstantRouteHandlerType,\n type InstantRouteHandlerBody,\n type StoreInterfaceStoreName,\n InstantWritableStream,\n InstantReadableStream,\n type Logger,\n} from '@sidekickdb/core';\n\nimport { InstantReactAbstractDatabase } from '@sidekickdb/react-common';\nimport InstantReactWebDatabase from './InstantReactWebDatabase.ts';\nimport { init, init_experimental } from './init.ts';\nimport { Cursors } from './Cursors.tsx';\n\nexport {\n id,\n tx,\n lookup,\n init,\n init_experimental,\n InstantReactWebDatabase,\n Cursors,\n i,\n\n // error\n InstantAPIError,\n\n // internal\n InstantReactAbstractDatabase,\n\n // sync table enums\n SyncTableCallbackEventType,\n\n // warnings\n setInstantWarningsEnabled,\n\n // types\n type Config,\n type InstantConfig,\n type InstantUnknownSchemaDef,\n type Query,\n type QueryResponse,\n type InstantObject,\n type User,\n type AuthState,\n type ConnectionStatus,\n type AppStatusState,\n type InstantQuery,\n type InstantQueryResult,\n type InstantSchema,\n type InstantEntity,\n type InstantSchemaDatabase,\n type IInstantDatabase,\n type InstaQLParams,\n type ValidQuery,\n type InstaQLFields,\n\n // presence types\n type PresencePeer,\n\n // schema types\n type AttrsDefs,\n type CardinalityKind,\n type DataAttrDef,\n type EntitiesDef,\n type EntitiesWithLinks,\n type EntityDef,\n type InstantGraph,\n type LinkAttrDef,\n type LinkDef,\n type LinksDef,\n type ResolveAttrs,\n type ValueTypes,\n type InstaQLEntity,\n type InstaQLResult,\n type InstaQLEntitySubquery,\n type RoomsOf,\n type RoomsDef,\n type TransactionChunk,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type RoomHandle,\n type InstantUnknownSchema,\n type InstantSchemaDef,\n type BackwardsCompatibleSchema,\n type InstantRules,\n type UpdateParams,\n type LinkParams,\n type CreateParams,\n type CheckMagicCodeParams,\n type CheckMagicCodeResponse,\n type ExchangeCodeForTokenParams,\n type SendMagicCodeParams,\n type SendMagicCodeResponse,\n type SignInWithIdTokenParams,\n type VerifyMagicCodeParams,\n type VerifyResponse,\n\n // storage types\n type FileOpts,\n type UploadFileResponse,\n type DeleteFileResponse,\n\n // stream types\n type CreateReadStreamOpts,\n type CreateWriteStreamOpts,\n type InstantWritableStream,\n type InstantReadableStream,\n\n // custom store\n StoreInterface,\n type StoreInterfaceStoreName,\n\n // sync table types\n type SyncTableCallback,\n type SyncTableCallbackEvent,\n type SyncTableInitialSyncBatch,\n type SyncTableInitialSyncComplete,\n type SyncTableSyncTransaction,\n type SyncTableLoadFromStorage,\n type SyncTableSetupError,\n\n // Server helper\n createInstantRouteHandler,\n type InstantRouteHandlerPayloadByType,\n type InstantRouteHandlerType,\n type InstantRouteHandlerBody,\n\n // logger\n type Logger,\n};\n"]}
@@ -0,0 +1,41 @@
1
+ import type { InstantConfig, InstantSchemaDef, InstantUnknownSchema } from '@sidekickdb/core';
2
+ import InstantReactWebDatabase from './InstantReactWebDatabase.ts';
3
+ /**
4
+ *
5
+ * The first step: init your application!
6
+ *
7
+ * Find your `appId` in your SidekickDB dashboard.
8
+ *
9
+ * @example
10
+ * import { init } from "@sidekickdb/react"
11
+ *
12
+ * const db = init({ appId: "my-app-id", apiURI: "https://sidekick.example.com" })
13
+ *
14
+ * // You can also provide a schema for type safety and editor autocomplete!
15
+ *
16
+ * import { init } from "@sidekickdb/react"
17
+ * import schema from ""../instant.schema.ts";
18
+ *
19
+ * const db = init({ appId: "my-app-id", apiURI: "https://sidekick.example.com", schema })
20
+ *
21
+ * // To learn more: https://sidekickdb.co/docs/modeling-data
22
+ */
23
+ export declare function init<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema, UseDates extends boolean = false>(config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {
24
+ useDateObjects?: UseDates;
25
+ }): InstantReactWebDatabase<Schema, UseDates, InstantConfig<Schema, UseDates>>;
26
+ /**
27
+ * @deprecated
28
+ * `init_experimental` is deprecated. You can replace it with `init`.
29
+ *
30
+ * @example
31
+ *
32
+ * // Before
33
+ * import { init_experimental } from "@sidekickdb/react"
34
+ * const db = init_experimental({ ... });
35
+ *
36
+ * // After
37
+ * import { init } from "@sidekickdb/react"
38
+ * const db = init({ ... });
39
+ */
40
+ export declare const init_experimental: typeof init;
41
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AAGnE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,IAAI,CAClB,MAAM,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,oBAAoB,EACrE,QAAQ,SAAS,OAAO,GAAG,KAAK,EAIhC,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,gBAAgB,CAAC,GAAG;IAChE,cAAc,CAAC,EAAE,QAAQ,CAAC;CAC3B,GACA,uBAAuB,CAAC,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAY5E;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,aAAO,CAAC"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.init_experimental = void 0;
7
+ exports.init = init;
8
+ const InstantReactWebDatabase_ts_1 = __importDefault(require("./InstantReactWebDatabase.js"));
9
+ const version_ts_1 = __importDefault(require("./version.js"));
10
+ /**
11
+ *
12
+ * The first step: init your application!
13
+ *
14
+ * Find your `appId` in your SidekickDB dashboard.
15
+ *
16
+ * @example
17
+ * import { init } from "@sidekickdb/react"
18
+ *
19
+ * const db = init({ appId: "my-app-id", apiURI: "https://sidekick.example.com" })
20
+ *
21
+ * // You can also provide a schema for type safety and editor autocomplete!
22
+ *
23
+ * import { init } from "@sidekickdb/react"
24
+ * import schema from ""../instant.schema.ts";
25
+ *
26
+ * const db = init({ appId: "my-app-id", apiURI: "https://sidekick.example.com", schema })
27
+ *
28
+ * // To learn more: https://sidekickdb.co/docs/modeling-data
29
+ */
30
+ function init(
31
+ // Allows config with missing `useDateObjects`, but keeps `UseDates`
32
+ // as a non-nullable in the InstantConfig type.
33
+ config) {
34
+ const configStrict = {
35
+ ...config,
36
+ useDateObjects: (config.useDateObjects ?? false),
37
+ };
38
+ return new InstantReactWebDatabase_ts_1.default(configStrict, {
39
+ '@instantdb/react': version_ts_1.default,
40
+ });
41
+ }
42
+ /**
43
+ * @deprecated
44
+ * `init_experimental` is deprecated. You can replace it with `init`.
45
+ *
46
+ * @example
47
+ *
48
+ * // Before
49
+ * import { init_experimental } from "@sidekickdb/react"
50
+ * const db = init_experimental({ ... });
51
+ *
52
+ * // After
53
+ * import { init } from "@sidekickdb/react"
54
+ * const db = init({ ... });
55
+ */
56
+ exports.init_experimental = init;
57
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":";;;;;;AA6BA,oBAqBC;AA5CD,8FAAmE;AACnE,8DAAmC;AAEnC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,IAAI;AAIlB,oEAAoE;AACpE,+CAA+C;AAC/C,MAEC;IAED,MAAM,YAAY,GAAG;QACnB,GAAG,MAAM;QACT,cAAc,EAAE,CAAC,MAAM,CAAC,cAAc,IAAI,KAAK,CAAa;KAC7D,CAAC;IACF,OAAO,IAAI,oCAAuB,CAIhC,YAAY,EAAE;QACd,kBAAkB,EAAE,oBAAO;KAC5B,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;GAaG;AACU,QAAA,iBAAiB,GAAG,IAAI,CAAC","sourcesContent":["import type {\n InstantConfig,\n InstantSchemaDef,\n InstantUnknownSchema,\n} from '@sidekickdb/core';\n\nimport InstantReactWebDatabase from './InstantReactWebDatabase.ts';\nimport version from './version.ts';\n\n/**\n *\n * The first step: init your application!\n *\n * Find your `appId` in your SidekickDB dashboard.\n *\n * @example\n * import { init } from \"@sidekickdb/react\"\n *\n * const db = init({ appId: \"my-app-id\", apiURI: \"https://sidekick.example.com\" })\n *\n * // You can also provide a schema for type safety and editor autocomplete!\n *\n * import { init } from \"@sidekickdb/react\"\n * import schema from \"\"../instant.schema.ts\";\n *\n * const db = init({ appId: \"my-app-id\", apiURI: \"https://sidekick.example.com\", schema })\n *\n * // To learn more: https://sidekickdb.co/docs/modeling-data\n */\nexport function init<\n Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema,\n UseDates extends boolean = false,\n>(\n // Allows config with missing `useDateObjects`, but keeps `UseDates`\n // as a non-nullable in the InstantConfig type.\n config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {\n useDateObjects?: UseDates;\n },\n): InstantReactWebDatabase<Schema, UseDates, InstantConfig<Schema, UseDates>> {\n const configStrict = {\n ...config,\n useDateObjects: (config.useDateObjects ?? false) as UseDates,\n };\n return new InstantReactWebDatabase<\n Schema,\n UseDates,\n InstantConfig<Schema, UseDates>\n >(configStrict, {\n '@instantdb/react': version,\n });\n}\n\n/**\n * @deprecated\n * `init_experimental` is deprecated. You can replace it with `init`.\n *\n * @example\n *\n * // Before\n * import { init_experimental } from \"@sidekickdb/react\"\n * const db = init_experimental({ ... });\n *\n * // After\n * import { init } from \"@sidekickdb/react\"\n * const db = init({ ... });\n */\nexport const init_experimental = init;\n"]}
@@ -0,0 +1,66 @@
1
+ export declare const isServer: boolean;
2
+ import * as React from 'react';
3
+ interface DataTransformer {
4
+ serialize: (object: any) => any;
5
+ deserialize: (object: any) => any;
6
+ }
7
+ interface HydrationStreamContext<TShape> {
8
+ id: string;
9
+ stream: {
10
+ /**
11
+ * **Server method**
12
+ * Push a new entry to the stream
13
+ * Will be ignored on the client
14
+ */
15
+ push: (...shape: Array<TShape>) => void;
16
+ };
17
+ }
18
+ export interface HydrationStreamProviderProps<TShape> {
19
+ children: React.ReactNode;
20
+ /**
21
+ * Optional transformer to serialize/deserialize the data
22
+ * Example devalue, superjson et al
23
+ */
24
+ transformer?: DataTransformer;
25
+ /**
26
+ * **Client method**
27
+ * Called in the browser when new entries are received
28
+ */
29
+ onEntries: (entries: Array<TShape>) => void;
30
+ /**
31
+ * **Server method**
32
+ * onFlush is called on the server when the cache is flushed
33
+ */
34
+ onFlush?: () => Array<TShape>;
35
+ /**
36
+ * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
37
+ */
38
+ nonce?: string;
39
+ }
40
+ export declare function createHydrationStreamProvider<TShape>(): {
41
+ Provider: (props: {
42
+ children: React.ReactNode;
43
+ /**
44
+ * Optional transformer to serialize/deserialize the data
45
+ * Example devalue, superjson et al
46
+ */
47
+ transformer?: DataTransformer;
48
+ /**
49
+ * **Client method**
50
+ * Called in the browser when new entries are received
51
+ */
52
+ onEntries: (entries: Array<TShape>) => void;
53
+ /**
54
+ * **Server method**
55
+ * onFlush is called on the server when the cache is flushed
56
+ */
57
+ onFlush?: () => Array<TShape>;
58
+ /**
59
+ * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
60
+ */
61
+ nonce?: string;
62
+ }) => import("react/jsx-runtime").JSX.Element;
63
+ context: React.Context<HydrationStreamContext<TShape>>;
64
+ };
65
+ export {};
66
+ //# sourceMappingURL=HydrationStreamProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HydrationStreamProvider.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/HydrationStreamProvider.tsx"],"names":[],"mappings":"AAQA,eAAO,MAAM,QAAQ,SAAwD,CAAC;AAI9E,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,UAAU,eAAe;IACvB,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAChC,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;CACnC;AAWD,UAAU,sBAAsB,CAAC,MAAM;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE;QACN;;;;WAIG;QACH,IAAI,EAAE,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;KACzC,CAAC;CACH;AAED,MAAM,WAAW,4BAA4B,CAAC,MAAM;IAClD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;OAGG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B;;;OAGG;IACH,SAAS,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAC5C;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,6BAA6B,CAAC,MAAM;sBAaD;QAC/C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B;;;WAGG;QACH,WAAW,CAAC,EAAE,eAAe,CAAC;QAC9B;;;WAGG;QACH,SAAS,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;QAC5C;;;WAGG;QACH,OAAO,CAAC,EAAE,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9B;;WAEG;QACH,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB;;EAmGF"}
@@ -0,0 +1,134 @@
1
+ 'use client';
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.isServer = void 0;
38
+ exports.createHydrationStreamProvider = createHydrationStreamProvider;
39
+ const jsx_runtime_1 = require("react/jsx-runtime");
40
+ // This allows us to send serialized json from the server to the client using 'useServerInsertedHTML'
41
+ // We are allowed to send whatever json we want, however it must be triggered at the same time as the client is recieving new html to display
42
+ // after a suspsense boundary resolves
43
+ // We do this to send a list of triples and attrs for each query that the server made so they can be pre-filled on the client render.
44
+ // useServerInsertedHTML is called whenever a suspense boundary resolves, resulting in new html being streamed down to the client.
45
+ exports.isServer = typeof window === 'undefined' || 'Deno' in globalThis;
46
+ const navigation_js_1 = require("next/navigation.js");
47
+ const React = __importStar(require("react"));
48
+ const htmlescape_js_1 = require("./htmlescape.js");
49
+ const serializedSymbol = Symbol('serialized');
50
+ function createHydrationStreamProvider() {
51
+ const context = React.createContext(null);
52
+ /**
53
+
54
+ * 1. (Happens on server): `useServerInsertedHTML()` is called **on the server** whenever a `Suspense`-boundary completes
55
+ * - This means that we might have some new entries in the cache that needs to be flushed
56
+ * - We pass these to the client by inserting a `<script>`-tag where we do `window[id].push(serializedVersionOfCache)`
57
+ * 2. (Happens in browser) In `useEffect()`:
58
+ * - We check if `window[id]` is set to an array and call `push()` on all the entries which will call `onEntries()` with the new entries
59
+ * - We replace `window[id]` with a `push()`-method that will be called whenever new entries are received
60
+ **/
61
+ function UseClientHydrationStreamProvider(props) {
62
+ // unique id for the cache provider
63
+ const id = `__RQ${React.useId()}`;
64
+ const idJSON = (0, htmlescape_js_1.htmlEscapeJsonString)(JSON.stringify(id));
65
+ const [transformer] = React.useState(() => (props.transformer ?? {
66
+ // noop
67
+ serialize: (obj) => obj,
68
+ deserialize: (obj) => obj,
69
+ }));
70
+ // <server stuff>
71
+ const [stream] = React.useState(() => {
72
+ if (!exports.isServer) {
73
+ return {
74
+ push() {
75
+ // no-op on the client
76
+ },
77
+ };
78
+ }
79
+ return [];
80
+ });
81
+ const count = React.useRef(0);
82
+ (0, navigation_js_1.useServerInsertedHTML)(() => {
83
+ // This only happens on the server
84
+ stream.push(...(props.onFlush?.() ?? []));
85
+ if (!stream.length) {
86
+ return null;
87
+ }
88
+ const serializedCacheArgs = stream
89
+ .map((entry) => transformer.serialize(entry))
90
+ .map((entry) => JSON.stringify(entry))
91
+ .join(',');
92
+ // Flush stream
93
+ // eslint-disable-next-line react-hooks/immutability
94
+ stream.length = 0;
95
+ const html = [
96
+ `window[${idJSON}] = window[${idJSON}] || [];`,
97
+ `window[${idJSON}].push(${(0, htmlescape_js_1.htmlEscapeJsonString)(serializedCacheArgs)});`,
98
+ ];
99
+ return ((0, jsx_runtime_1.jsx)("script", { nonce: props.nonce, dangerouslySetInnerHTML: {
100
+ __html: html.join(''),
101
+ } }, count.current++));
102
+ });
103
+ // </server stuff>
104
+ // <client stuff>
105
+ // Setup and run the onEntries handler on the client only, but do it during
106
+ // the initial render so children have access to the data immediately
107
+ // This is important to avoid the client suspending during the initial render
108
+ // if the data has not yet been hydrated.
109
+ if (!exports.isServer) {
110
+ const win = window;
111
+ if (!win[id]?.initialized) {
112
+ // Client: consume cache:
113
+ const onEntries = (...serializedEntries) => {
114
+ const entries = serializedEntries.map((serialized) => transformer.deserialize(serialized));
115
+ props.onEntries(entries);
116
+ };
117
+ const winStream = win[id] ?? [];
118
+ onEntries(...winStream);
119
+ // eslint-disable-next-line react-hooks/immutability
120
+ win[id] = {
121
+ initialized: true,
122
+ push: onEntries,
123
+ };
124
+ }
125
+ }
126
+ // </client stuff>
127
+ return ((0, jsx_runtime_1.jsx)(context.Provider, { value: { stream, id }, children: props.children }));
128
+ }
129
+ return {
130
+ Provider: UseClientHydrationStreamProvider,
131
+ context,
132
+ };
133
+ }
134
+ //# sourceMappingURL=HydrationStreamProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HydrationStreamProvider.js","sourceRoot":"","sources":["../../../src/next-ssr/HydrationStreamProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEb,sEAqIC;;AArMD,qGAAqG;AACrG,6IAA6I;AAC7I,sCAAsC;AACtC,qIAAqI;AACrI,kIAAkI;AAErH,QAAA,QAAQ,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,IAAI,UAAU,CAAC;AAE9E,sDAA2D;AAE3D,6CAA+B;AAC/B,mDAAuD;AAEvD,MAAM,gBAAgB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAmD9C,SAAgB,6BAA6B;IAC3C,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CACjC,IAAW,CACZ,CAAC;IACF;;;;;;;;QAQI;IACJ,SAAS,gCAAgC,CAAC,KAqBzC;QACC,mCAAmC;QACnC,MAAM,EAAE,GAAG,OAAO,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,IAAA,oCAAoB,EAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QAExD,MAAM,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC,QAAQ,CAClC,GAAG,EAAE,CACH,CAAC,KAAK,CAAC,WAAW,IAAI;YACpB,OAAO;YACP,SAAS,EAAE,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG;YAC5B,WAAW,EAAE,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG;SAC/B,CAA4C,CAChD,CAAC;QAEF,iBAAiB;QACjB,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAgB,GAAG,EAAE;YAClD,IAAI,CAAC,gBAAQ,EAAE,CAAC;gB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,MAAM,GAAG,GAAG,MAAa,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC;gBAC1B,yBAAyB;gBACzB,MAAM,SAAS,GAAG,CAAC,GAAG,iBAA4C,EAAE,EAAE;oBACpE,MAAM,OAAO,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CACnD,WAAW,CAAC,WAAW,CAAC,UAAU,CAAC,CACpC,CAAC;oBACF,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;gBAC3B,CAAC,CAAC;gBAEF,MAAM,SAAS,GAA8B,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;gBAE3D,SAAS,CAAC,GAAG,SAAS,CAAC,CAAC;gBAExB,oDAAoD;gBACpD,GAAG,CAAC,EAAE,CAAC,GAAG;oBACR,WAAW,EAAE,IAAI;oBACjB,IAAI,EAAE,SAAS;iBAChB,CAAC;YACJ,CAAC;QACH,CAAC;QACD,kBAAkB;QAElB,OAAO,CACL,uBAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,YACpC,KAAK,CAAC,QAAQ,GACE,CACpB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,gCAAgC;QAC1C,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\n// This allows us to send serialized json from the server to the client using 'useServerInsertedHTML'\n// We are allowed to send whatever json we want, however it must be triggered at the same time as the client is recieving new html to display\n// after a suspsense boundary resolves\n// We do this to send a list of triples and attrs for each query that the server made so they can be pre-filled on the client render.\n// useServerInsertedHTML is called whenever a suspense boundary resolves, resulting in new html being streamed down to the client.\n\nexport const isServer = typeof window === 'undefined' || 'Deno' in globalThis;\n\nimport { useServerInsertedHTML } from 'next/navigation.js';\n\nimport * as React from 'react';\nimport { htmlEscapeJsonString } from './htmlescape.js';\n\nconst serializedSymbol = Symbol('serialized');\n\ninterface DataTransformer {\n serialize: (object: any) => any;\n deserialize: (object: any) => any;\n}\n\ntype Serialized<TData> = unknown & {\n [serializedSymbol]: TData;\n};\n\ninterface TypedDataTransformer<TData> {\n serialize: (obj: TData) => Serialized<TData>;\n deserialize: (obj: Serialized<TData>) => TData;\n}\n\ninterface HydrationStreamContext<TShape> {\n id: string;\n stream: {\n /**\n * **Server method**\n * Push a new entry to the stream\n * Will be ignored on the client\n */\n push: (...shape: Array<TShape>) => void;\n };\n}\n\nexport interface HydrationStreamProviderProps<TShape> {\n children: React.ReactNode;\n /**\n * Optional transformer to serialize/deserialize the data\n * Example devalue, superjson et al\n */\n transformer?: DataTransformer;\n /**\n * **Client method**\n * Called in the browser when new entries are received\n */\n onEntries: (entries: Array<TShape>) => void;\n /**\n * **Server method**\n * onFlush is called on the server when the cache is flushed\n */\n onFlush?: () => Array<TShape>;\n /**\n * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced\n */\n nonce?: string;\n}\n\nexport function createHydrationStreamProvider<TShape>() {\n const context = React.createContext<HydrationStreamContext<TShape>>(\n null as any,\n );\n /**\n\n * 1. (Happens on server): `useServerInsertedHTML()` is called **on the server** whenever a `Suspense`-boundary completes\n * - This means that we might have some new entries in the cache that needs to be flushed\n * - We pass these to the client by inserting a `<script>`-tag where we do `window[id].push(serializedVersionOfCache)`\n * 2. (Happens in browser) In `useEffect()`:\n * - We check if `window[id]` is set to an array and call `push()` on all the entries which will call `onEntries()` with the new entries\n * - We replace `window[id]` with a `push()`-method that will be called whenever new entries are received\n **/\n function UseClientHydrationStreamProvider(props: {\n children: React.ReactNode;\n /**\n * Optional transformer to serialize/deserialize the data\n * Example devalue, superjson et al\n */\n transformer?: DataTransformer;\n /**\n * **Client method**\n * Called in the browser when new entries are received\n */\n onEntries: (entries: Array<TShape>) => void;\n /**\n * **Server method**\n * onFlush is called on the server when the cache is flushed\n */\n onFlush?: () => Array<TShape>;\n /**\n * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced\n */\n nonce?: string;\n }) {\n // unique id for the cache provider\n const id = `__RQ${React.useId()}`;\n const idJSON = htmlEscapeJsonString(JSON.stringify(id));\n\n const [transformer] = React.useState(\n () =>\n (props.transformer ?? {\n // noop\n serialize: (obj: any) => obj,\n deserialize: (obj: any) => obj,\n }) as unknown as TypedDataTransformer<TShape>,\n );\n\n // <server stuff>\n const [stream] = React.useState<Array<TShape>>(() => {\n if (!isServer) {\n return {\n push() {\n // no-op on the client\n },\n } as unknown as Array<TShape>;\n }\n return [];\n });\n const count = React.useRef(0);\n useServerInsertedHTML(() => {\n // This only happens on the server\n stream.push(...(props.onFlush?.() ?? []));\n\n if (!stream.length) {\n return null;\n }\n\n const serializedCacheArgs = stream\n .map((entry) => transformer.serialize(entry))\n .map((entry) => JSON.stringify(entry))\n .join(',');\n\n // Flush stream\n // eslint-disable-next-line react-hooks/immutability\n stream.length = 0;\n\n const html: Array<string> = [\n `window[${idJSON}] = window[${idJSON}] || [];`,\n `window[${idJSON}].push(${htmlEscapeJsonString(serializedCacheArgs)});`,\n ];\n return (\n <script\n key={count.current++}\n nonce={props.nonce}\n dangerouslySetInnerHTML={{\n __html: html.join(''),\n }}\n />\n );\n });\n // </server stuff>\n\n // <client stuff>\n // Setup and run the onEntries handler on the client only, but do it during\n // the initial render so children have access to the data immediately\n // This is important to avoid the client suspending during the initial render\n // if the data has not yet been hydrated.\n if (!isServer) {\n const win = window as any;\n if (!win[id]?.initialized) {\n // Client: consume cache:\n const onEntries = (...serializedEntries: Array<Serialized<TShape>>) => {\n const entries = serializedEntries.map((serialized) =>\n transformer.deserialize(serialized),\n );\n props.onEntries(entries);\n };\n\n const winStream: Array<Serialized<TShape>> = win[id] ?? [];\n\n onEntries(...winStream);\n\n // eslint-disable-next-line react-hooks/immutability\n win[id] = {\n initialized: true,\n push: onEntries,\n };\n }\n }\n // </client stuff>\n\n return (\n <context.Provider value={{ stream, id }}>\n {props.children}\n </context.Provider>\n );\n }\n\n return {\n Provider: UseClientHydrationStreamProvider,\n context,\n };\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { AuthState, InstantSchemaDef, InstaQLResponse, PageInfoResponse, RuleParams, ValidQuery } from '@sidekickdb/core';
2
+ import InstantReactWebDatabase from '../InstantReactWebDatabase.ts';
3
+ export declare class InstantNextDatabase<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean> extends InstantReactWebDatabase<Schema, UseDates> {
4
+ useSuspenseQuery: <Q extends ValidQuery<Q, Schema>>(q: Q, opts?: {
5
+ ruleParams: RuleParams;
6
+ }) => {
7
+ data: InstaQLResponse<Schema, Q, NonNullable<UseDates>>;
8
+ pageInfo?: PageInfoResponse<Q>;
9
+ };
10
+ useAuth: () => AuthState;
11
+ }
12
+ //# sourceMappingURL=InstantNextDatabase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstantNextDatabase.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/InstantNextDatabase.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,UAAU,EACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,uBAAuB,MAAM,+BAA+B,CAAC;AAIpE,qBAAa,mBAAmB,CAC9B,MAAM,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC9C,QAAQ,SAAS,OAAO,CACxB,SAAQ,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1C,gBAAgB,GAAI,CAAC,SAAS,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,EACxD,GAAG,CAAC,EACJ,OAAO;QACL,UAAU,EAAE,UAAU,CAAC;KACxB,KACA;QACD,IAAI,EAAE,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;QACxD,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;KAChC,CAQC;IAEF,OAAO,QAAO,SAAS,CAoBrB;CACH"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.InstantNextDatabase = void 0;
7
+ const InstantReactWebDatabase_ts_1 = __importDefault(require("../InstantReactWebDatabase.js"));
8
+ const react_1 = require("react");
9
+ const InstantSuspenseProvider_tsx_1 = require("./InstantSuspenseProvider.js");
10
+ class InstantNextDatabase extends InstantReactWebDatabase_ts_1.default {
11
+ useSuspenseQuery = (q, opts) => {
12
+ const ctx = (0, react_1.useContext)(InstantSuspenseProvider_tsx_1.SuspsenseQueryContext);
13
+ if (!ctx) {
14
+ throw new Error('useSuspenseQuery must be used within a SuspenseQueryProvider');
15
+ }
16
+ return ctx.useSuspenseQuery(q, opts);
17
+ };
18
+ useAuth = () => {
19
+ const ctx = (0, react_1.useContext)(InstantSuspenseProvider_tsx_1.SuspsenseQueryContext);
20
+ const realAuthResult = this._useAuth();
21
+ if (!ctx) {
22
+ return realAuthResult;
23
+ }
24
+ const { ssrUser } = ctx;
25
+ if (ssrUser === undefined) {
26
+ return realAuthResult;
27
+ }
28
+ if (realAuthResult.isLoading) {
29
+ return {
30
+ error: undefined,
31
+ isLoading: false,
32
+ user: ssrUser ?? undefined, // null -> undefined for the response
33
+ };
34
+ }
35
+ return realAuthResult;
36
+ };
37
+ }
38
+ exports.InstantNextDatabase = InstantNextDatabase;
39
+ //# sourceMappingURL=InstantNextDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstantNextDatabase.js","sourceRoot":"","sources":["../../../src/next-ssr/InstantNextDatabase.tsx"],"names":[],"mappings":";;;;;;AAQA,+FAAoE;AACpE,iCAAmC;AACnC,8EAAsE;AAEtE,MAAa,mBAGX,SAAQ,oCAAyC;IAC1C,gBAAgB,GAAG,CACxB,CAAI,EACJ,IAEC,EAID,EAAE;QACF,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,mDAAqB,CAAC,CAAC;QAC9C,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAQ,CAAC;IAC9C,CAAC,CAAC;IAEF,OAAO,GAAG,GAAc,EAAE;QACxB,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,mDAAqB,CAAC,CAAC;QAC9C,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;QACxB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,cAAc,CAAC;QACxB,CAAC;QACD,IAAI,cAAc,CAAC,SAAS,EAAE,CAAC;YAC7B,OAAO;gBACL,KAAK,EAAE,SAAS;gBAChB,SAAS,EAAE,KAAK;gBAChB,IAAI,EAAE,OAAO,IAAI,SAAS,EAAE,qCAAqC;aAClE,CAAC;QACJ,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC,CAAC;CACH;AA3CD,kDA2CC","sourcesContent":["import {\n AuthState,\n InstantSchemaDef,\n InstaQLResponse,\n PageInfoResponse,\n RuleParams,\n ValidQuery,\n} from '@sidekickdb/core';\nimport InstantReactWebDatabase from '../InstantReactWebDatabase.ts';\nimport { useContext } from 'react';\nimport { SuspsenseQueryContext } from './InstantSuspenseProvider.tsx';\n\nexport class InstantNextDatabase<\n Schema extends InstantSchemaDef<any, any, any>,\n UseDates extends boolean,\n> extends InstantReactWebDatabase<Schema, UseDates> {\n public useSuspenseQuery = <Q extends ValidQuery<Q, Schema>>(\n q: Q,\n opts?: {\n ruleParams: RuleParams;\n },\n ): {\n data: InstaQLResponse<Schema, Q, NonNullable<UseDates>>;\n pageInfo?: PageInfoResponse<Q>;\n } => {\n const ctx = useContext(SuspsenseQueryContext);\n if (!ctx) {\n throw new Error(\n 'useSuspenseQuery must be used within a SuspenseQueryProvider',\n );\n }\n return ctx.useSuspenseQuery(q, opts) as any;\n };\n\n useAuth = (): AuthState => {\n const ctx = useContext(SuspsenseQueryContext);\n const realAuthResult = this._useAuth();\n if (!ctx) {\n return realAuthResult;\n }\n\n const { ssrUser } = ctx;\n if (ssrUser === undefined) {\n return realAuthResult;\n }\n if (realAuthResult.isLoading) {\n return {\n error: undefined,\n isLoading: false,\n user: ssrUser ?? undefined, // null -> undefined for the response\n };\n }\n\n return realAuthResult;\n };\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import { InstantSchemaDef, InstaQLResponse, PageInfoResponse, RuleParams, User, ValidQuery } from '@sidekickdb/core';
2
+ import InstantReactWebDatabase from '../InstantReactWebDatabase.ts';
3
+ type InstantSuspenseProviderProps<Schema extends InstantSchemaDef<any, any, any>> = {
4
+ nonce?: string;
5
+ children: React.ReactNode;
6
+ db: InstantReactWebDatabase<Schema, any>;
7
+ user?: User | null;
8
+ };
9
+ type SuspenseQueryContextValue = {
10
+ useSuspenseQuery: (query: any, opts?: SuspenseQueryOpts) => any;
11
+ ssrUser: User | null | undefined;
12
+ };
13
+ export declare const SuspsenseQueryContext: import("react").Context<SuspenseQueryContextValue | null>;
14
+ export declare const createUseSuspenseQuery: <Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean>(_db: InstantReactWebDatabase<Schema, UseDates>) => (<Q extends ValidQuery<Q, Schema>>(q: Q, opts?: {
15
+ ruleParams: RuleParams;
16
+ }) => {
17
+ data: InstaQLResponse<Schema, Q, NonNullable<UseDates>>;
18
+ pageInfo?: PageInfoResponse<Q>;
19
+ });
20
+ type SuspenseQueryOpts = {
21
+ ruleParams: RuleParams;
22
+ };
23
+ export declare const InstantSuspenseProvider: (props: InstantSuspenseProviderProps<any>) => import("react/jsx-runtime").JSX.Element;
24
+ export {};
25
+ //# sourceMappingURL=InstantSuspenseProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstantSuspenseProvider.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/InstantSuspenseProvider.tsx"],"names":[],"mappings":"AAGA,OAAO,EAGL,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,IAAI,EACJ,UAAU,EACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,uBAAuB,MAAM,+BAA+B,CAAC;AAmBpE,KAAK,4BAA4B,CAC/B,MAAM,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAC5C;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,EAAE,EAAE,uBAAuB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,CAAC;AAIF,KAAK,yBAAyB,GAAG;IAC/B,gBAAgB,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,GAAG,CAAC;IAChE,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,qBAAqB,2DACqB,CAAC;AAGxD,eAAO,MAAM,sBAAsB,GACjC,MAAM,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC9C,QAAQ,SAAS,OAAO,EAExB,KAAK,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,KAC7C,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,EAClC,CAAC,EAAE,CAAC,EACJ,IAAI,CAAC,EAAE;IACL,UAAU,EAAE,UAAU,CAAC;CACxB,KACE;IACH,IAAI,EAAE,eAAe,CAAC,MAAM,E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