syncorejs 0.1.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.
- package/README.md +30 -0
- package/dist/_vendor/core/_virtual/_rolldown/runtime.mjs +27 -0
- package/dist/_vendor/core/cli.d.mts +5 -0
- package/dist/_vendor/core/cli.d.mts.map +1 -0
- package/dist/_vendor/core/cli.mjs +1196 -0
- package/dist/_vendor/core/cli.mjs.map +1 -0
- package/dist/_vendor/core/index.d.mts +7 -0
- package/dist/_vendor/core/index.mjs +25 -0
- package/dist/_vendor/core/index.mjs.map +1 -0
- package/dist/_vendor/core/runtime/devtools.d.mts +15 -0
- package/dist/_vendor/core/runtime/devtools.d.mts.map +1 -0
- package/dist/_vendor/core/runtime/devtools.mjs +300 -0
- package/dist/_vendor/core/runtime/devtools.mjs.map +1 -0
- package/dist/_vendor/core/runtime/functions.d.mts +123 -0
- package/dist/_vendor/core/runtime/functions.d.mts.map +1 -0
- package/dist/_vendor/core/runtime/functions.mjs +71 -0
- package/dist/_vendor/core/runtime/functions.mjs.map +1 -0
- package/dist/_vendor/core/runtime/id.d.mts +13 -0
- package/dist/_vendor/core/runtime/id.d.mts.map +1 -0
- package/dist/_vendor/core/runtime/id.mjs +28 -0
- package/dist/_vendor/core/runtime/id.mjs.map +1 -0
- package/dist/_vendor/core/runtime/runtime.d.mts +370 -0
- package/dist/_vendor/core/runtime/runtime.d.mts.map +1 -0
- package/dist/_vendor/core/runtime/runtime.mjs +1143 -0
- package/dist/_vendor/core/runtime/runtime.mjs.map +1 -0
- package/dist/_vendor/devtools-protocol/index.d.ts +230 -0
- package/dist/_vendor/devtools-protocol/index.d.ts.map +1 -0
- package/dist/_vendor/devtools-protocol/index.js +0 -0
- package/dist/_vendor/next/config.d.ts +17 -0
- package/dist/_vendor/next/config.d.ts.map +1 -0
- package/dist/_vendor/next/config.js +73 -0
- package/dist/_vendor/next/config.js.map +1 -0
- package/dist/_vendor/next/index.d.ts +80 -0
- package/dist/_vendor/next/index.d.ts.map +1 -0
- package/dist/_vendor/next/index.js +81 -0
- package/dist/_vendor/next/index.js.map +1 -0
- package/dist/_vendor/platform-expo/index.d.ts +97 -0
- package/dist/_vendor/platform-expo/index.d.ts.map +1 -0
- package/dist/_vendor/platform-expo/index.js +197 -0
- package/dist/_vendor/platform-expo/index.js.map +1 -0
- package/dist/_vendor/platform-expo/react.d.ts +26 -0
- package/dist/_vendor/platform-expo/react.d.ts.map +1 -0
- package/dist/_vendor/platform-expo/react.js +30 -0
- package/dist/_vendor/platform-expo/react.js.map +1 -0
- package/dist/_vendor/platform-node/index.d.mts +145 -0
- package/dist/_vendor/platform-node/index.d.mts.map +1 -0
- package/dist/_vendor/platform-node/index.mjs +405 -0
- package/dist/_vendor/platform-node/index.mjs.map +1 -0
- package/dist/_vendor/platform-node/ipc-react.d.mts +25 -0
- package/dist/_vendor/platform-node/ipc-react.d.mts.map +1 -0
- package/dist/_vendor/platform-node/ipc-react.mjs +21 -0
- package/dist/_vendor/platform-node/ipc-react.mjs.map +1 -0
- package/dist/_vendor/platform-node/ipc.d.mts +75 -0
- package/dist/_vendor/platform-node/ipc.d.mts.map +1 -0
- package/dist/_vendor/platform-node/ipc.mjs +343 -0
- package/dist/_vendor/platform-node/ipc.mjs.map +1 -0
- package/dist/_vendor/platform-web/index.d.ts +123 -0
- package/dist/_vendor/platform-web/index.d.ts.map +1 -0
- package/dist/_vendor/platform-web/index.js +309 -0
- package/dist/_vendor/platform-web/index.js.map +1 -0
- package/dist/_vendor/platform-web/indexeddb.d.ts +25 -0
- package/dist/_vendor/platform-web/indexeddb.d.ts.map +1 -0
- package/dist/_vendor/platform-web/indexeddb.js +125 -0
- package/dist/_vendor/platform-web/indexeddb.js.map +1 -0
- package/dist/_vendor/platform-web/opfs.d.ts +27 -0
- package/dist/_vendor/platform-web/opfs.d.ts.map +1 -0
- package/dist/_vendor/platform-web/opfs.js +146 -0
- package/dist/_vendor/platform-web/opfs.js.map +1 -0
- package/dist/_vendor/platform-web/persistence.d.ts +27 -0
- package/dist/_vendor/platform-web/persistence.d.ts.map +1 -0
- package/dist/_vendor/platform-web/persistence.js +23 -0
- package/dist/_vendor/platform-web/persistence.js.map +1 -0
- package/dist/_vendor/platform-web/react.d.ts +35 -0
- package/dist/_vendor/platform-web/react.d.ts.map +1 -0
- package/dist/_vendor/platform-web/react.js +42 -0
- package/dist/_vendor/platform-web/react.js.map +1 -0
- package/dist/_vendor/platform-web/sqljs.js +133 -0
- package/dist/_vendor/platform-web/sqljs.js.map +1 -0
- package/dist/_vendor/platform-web/worker.d.ts +78 -0
- package/dist/_vendor/platform-web/worker.d.ts.map +1 -0
- package/dist/_vendor/platform-web/worker.js +307 -0
- package/dist/_vendor/platform-web/worker.js.map +1 -0
- package/dist/_vendor/react/index.d.ts +58 -0
- package/dist/_vendor/react/index.d.ts.map +1 -0
- package/dist/_vendor/react/index.js +151 -0
- package/dist/_vendor/react/index.js.map +1 -0
- package/dist/_vendor/schema/definition.d.ts +98 -0
- package/dist/_vendor/schema/definition.d.ts.map +1 -0
- package/dist/_vendor/schema/definition.js +84 -0
- package/dist/_vendor/schema/definition.js.map +1 -0
- package/dist/_vendor/schema/index.d.ts +4 -0
- package/dist/_vendor/schema/index.js +4 -0
- package/dist/_vendor/schema/planner.d.ts +42 -0
- package/dist/_vendor/schema/planner.d.ts.map +1 -0
- package/dist/_vendor/schema/planner.js +131 -0
- package/dist/_vendor/schema/planner.js.map +1 -0
- package/dist/_vendor/schema/validators.d.ts +194 -0
- package/dist/_vendor/schema/validators.d.ts.map +1 -0
- package/dist/_vendor/schema/validators.js +158 -0
- package/dist/_vendor/schema/validators.js.map +1 -0
- package/dist/_vendor/svelte/index.d.ts +43 -0
- package/dist/_vendor/svelte/index.d.ts.map +1 -0
- package/dist/_vendor/svelte/index.js +75 -0
- package/dist/_vendor/svelte/index.js.map +1 -0
- package/dist/browser-react.d.ts +2 -0
- package/dist/browser-react.js +2 -0
- package/dist/browser.d.ts +12 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +10 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +11 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/src/cli.d.ts +5 -0
- package/dist/core/src/cli.d.ts.map +1 -0
- package/dist/core/src/cli.js +1196 -0
- package/dist/core/src/cli.js.map +1 -0
- package/dist/core/src/index.js +7 -0
- package/dist/core/src/runtime/devtools.d.ts +7 -0
- package/dist/core/src/runtime/devtools.d.ts.map +1 -0
- package/dist/core/src/runtime/devtools.js +300 -0
- package/dist/core/src/runtime/devtools.js.map +1 -0
- package/dist/core/src/runtime/functions.d.ts +123 -0
- package/dist/core/src/runtime/functions.d.ts.map +1 -0
- package/dist/core/src/runtime/functions.js +71 -0
- package/dist/core/src/runtime/functions.js.map +1 -0
- package/dist/core/src/runtime/id.d.ts +13 -0
- package/dist/core/src/runtime/id.d.ts.map +1 -0
- package/dist/core/src/runtime/id.js +28 -0
- package/dist/core/src/runtime/id.js.map +1 -0
- package/dist/core/src/runtime/runtime.d.ts +371 -0
- package/dist/core/src/runtime/runtime.d.ts.map +1 -0
- package/dist/core/src/runtime/runtime.js +1143 -0
- package/dist/core/src/runtime/runtime.js.map +1 -0
- package/dist/devtools-protocol/src/index.d.ts +201 -0
- package/dist/devtools-protocol/src/index.d.ts.map +1 -0
- package/dist/expo-react.d.ts +2 -0
- package/dist/expo-react.js +2 -0
- package/dist/expo.d.ts +2 -0
- package/dist/expo.js +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/next/src/config.d.ts +17 -0
- package/dist/next/src/config.d.ts.map +1 -0
- package/dist/next/src/config.js +73 -0
- package/dist/next/src/config.js.map +1 -0
- package/dist/next/src/index.d.ts +80 -0
- package/dist/next/src/index.d.ts.map +1 -0
- package/dist/next/src/index.js +82 -0
- package/dist/next/src/index.js.map +1 -0
- package/dist/next-config.d.ts +2 -0
- package/dist/next-config.js +2 -0
- package/dist/next.d.ts +3 -0
- package/dist/next.js +3 -0
- package/dist/node-ipc-react.d.ts +2 -0
- package/dist/node-ipc-react.js +2 -0
- package/dist/node-ipc.d.ts +2 -0
- package/dist/node-ipc.js +2 -0
- package/dist/node.d.ts +4 -0
- package/dist/node.js +3 -0
- package/dist/platform-expo/src/index.d.ts +96 -0
- package/dist/platform-expo/src/index.d.ts.map +1 -0
- package/dist/platform-expo/src/index.js +198 -0
- package/dist/platform-expo/src/index.js.map +1 -0
- package/dist/platform-expo/src/react.d.ts +26 -0
- package/dist/platform-expo/src/react.d.ts.map +1 -0
- package/dist/platform-expo/src/react.js +30 -0
- package/dist/platform-expo/src/react.js.map +1 -0
- package/dist/platform-node/src/index.d.ts +145 -0
- package/dist/platform-node/src/index.d.ts.map +1 -0
- package/dist/platform-node/src/index.js +407 -0
- package/dist/platform-node/src/index.js.map +1 -0
- package/dist/platform-node/src/ipc-react.d.ts +25 -0
- package/dist/platform-node/src/ipc-react.d.ts.map +1 -0
- package/dist/platform-node/src/ipc-react.js +21 -0
- package/dist/platform-node/src/ipc-react.js.map +1 -0
- package/dist/platform-node/src/ipc.d.ts +76 -0
- package/dist/platform-node/src/ipc.d.ts.map +1 -0
- package/dist/platform-node/src/ipc.js +344 -0
- package/dist/platform-node/src/ipc.js.map +1 -0
- package/dist/platform-web/src/index.d.ts +106 -0
- package/dist/platform-web/src/index.d.ts.map +1 -0
- package/dist/platform-web/src/index.js +311 -0
- package/dist/platform-web/src/index.js.map +1 -0
- package/dist/platform-web/src/indexeddb.js +125 -0
- package/dist/platform-web/src/indexeddb.js.map +1 -0
- package/dist/platform-web/src/opfs.js +146 -0
- package/dist/platform-web/src/opfs.js.map +1 -0
- package/dist/platform-web/src/persistence.d.ts +20 -0
- package/dist/platform-web/src/persistence.d.ts.map +1 -0
- package/dist/platform-web/src/persistence.js +23 -0
- package/dist/platform-web/src/persistence.js.map +1 -0
- package/dist/platform-web/src/react.d.ts +35 -0
- package/dist/platform-web/src/react.d.ts.map +1 -0
- package/dist/platform-web/src/react.js +42 -0
- package/dist/platform-web/src/react.js.map +1 -0
- package/dist/platform-web/src/sqljs.js +133 -0
- package/dist/platform-web/src/sqljs.js.map +1 -0
- package/dist/platform-web/src/worker.d.ts +79 -0
- package/dist/platform-web/src/worker.d.ts.map +1 -0
- package/dist/platform-web/src/worker.js +308 -0
- package/dist/platform-web/src/worker.js.map +1 -0
- package/dist/react/src/index.d.ts +59 -0
- package/dist/react/src/index.d.ts.map +1 -0
- package/dist/react/src/index.js +151 -0
- package/dist/react/src/index.js.map +1 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +2 -0
- package/dist/schema/src/definition.d.ts +98 -0
- package/dist/schema/src/definition.d.ts.map +1 -0
- package/dist/schema/src/definition.js +84 -0
- package/dist/schema/src/definition.js.map +1 -0
- package/dist/schema/src/planner.d.ts +42 -0
- package/dist/schema/src/planner.d.ts.map +1 -0
- package/dist/schema/src/planner.js +131 -0
- package/dist/schema/src/planner.js.map +1 -0
- package/dist/schema/src/validators.d.ts +194 -0
- package/dist/schema/src/validators.d.ts.map +1 -0
- package/dist/schema/src/validators.js +158 -0
- package/dist/schema/src/validators.js.map +1 -0
- package/dist/svelte/src/index.d.ts +44 -0
- package/dist/svelte/src/index.d.ts.map +1 -0
- package/dist/svelte/src/index.js +75 -0
- package/dist/svelte/src/index.js.map +1 -0
- package/dist/svelte.d.ts +2 -0
- package/dist/svelte.js +2 -0
- package/package.json +152 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
//#region ../schema/src/validators.ts
|
|
2
|
+
var StringValidator = class {
|
|
3
|
+
kind = "string";
|
|
4
|
+
parse(value, path = "value") {
|
|
5
|
+
if (typeof value !== "string") throw new Error(`${path} must be a string.`);
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var NumberValidator = class {
|
|
10
|
+
kind = "number";
|
|
11
|
+
parse(value, path = "value") {
|
|
12
|
+
if (typeof value !== "number" || Number.isNaN(value)) throw new Error(`${path} must be a number.`);
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var BooleanValidator = class {
|
|
17
|
+
kind = "boolean";
|
|
18
|
+
parse(value, path = "value") {
|
|
19
|
+
if (typeof value !== "boolean") throw new Error(`${path} must be a boolean.`);
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var NullValidator = class {
|
|
24
|
+
kind = "null";
|
|
25
|
+
parse(value, path = "value") {
|
|
26
|
+
if (value !== null) throw new Error(`${path} must be null.`);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var AnyValidator = class {
|
|
31
|
+
kind = "any";
|
|
32
|
+
parse(value) {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var LiteralValidator = class {
|
|
37
|
+
kind = "literal";
|
|
38
|
+
constructor(literalValue) {
|
|
39
|
+
this.literalValue = literalValue;
|
|
40
|
+
}
|
|
41
|
+
parse(value, path = "value") {
|
|
42
|
+
if (value !== this.literalValue) throw new Error(`${path} must equal ${String(this.literalValue)}.`);
|
|
43
|
+
return this.literalValue;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var ArrayValidator = class {
|
|
47
|
+
kind = "array";
|
|
48
|
+
constructor(itemValidator) {
|
|
49
|
+
this.itemValidator = itemValidator;
|
|
50
|
+
}
|
|
51
|
+
parse(value, path = "value") {
|
|
52
|
+
if (!Array.isArray(value)) throw new Error(`${path} must be an array.`);
|
|
53
|
+
return value.map((item, index) => this.itemValidator.parse(item, `${path}[${index}]`));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var ObjectValidator = class {
|
|
57
|
+
kind = "object";
|
|
58
|
+
constructor(shape) {
|
|
59
|
+
this.shape = shape;
|
|
60
|
+
}
|
|
61
|
+
parse(value, path = "value") {
|
|
62
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${path} must be an object.`);
|
|
63
|
+
const source = value;
|
|
64
|
+
const parsed = {};
|
|
65
|
+
for (const [key, validator] of Object.entries(this.shape)) {
|
|
66
|
+
if (validator.kind === "optional" && source[key] === void 0) continue;
|
|
67
|
+
parsed[key] = validator.parse(source[key], `${path}.${key}`);
|
|
68
|
+
}
|
|
69
|
+
return parsed;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var IdValidator = class {
|
|
73
|
+
kind = "id";
|
|
74
|
+
constructor(tableName) {
|
|
75
|
+
this.tableName = tableName;
|
|
76
|
+
}
|
|
77
|
+
parse(value, path = "value") {
|
|
78
|
+
if (typeof value !== "string" || value.length === 0) throw new Error(`${path} must be a non-empty id string.`);
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var OptionalValidator = class {
|
|
83
|
+
kind = "optional";
|
|
84
|
+
constructor(inner) {
|
|
85
|
+
this.inner = inner;
|
|
86
|
+
}
|
|
87
|
+
parse(value, path = "value") {
|
|
88
|
+
if (value === void 0) return;
|
|
89
|
+
return this.inner.parse(value, path);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
function isValidator(value) {
|
|
93
|
+
return typeof value.parse === "function";
|
|
94
|
+
}
|
|
95
|
+
function ensureObjectValidator(value) {
|
|
96
|
+
if (isValidator(value)) return value;
|
|
97
|
+
return new ObjectValidator(value);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Build runtime validators for schemas, function args, and return values.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* defineTable({
|
|
105
|
+
* text: v.string(),
|
|
106
|
+
* done: v.boolean(),
|
|
107
|
+
* ownerId: v.optional(v.id("users"))
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
const v = {
|
|
112
|
+
string: () => new StringValidator(),
|
|
113
|
+
number: () => new NumberValidator(),
|
|
114
|
+
boolean: () => new BooleanValidator(),
|
|
115
|
+
null: () => new NullValidator(),
|
|
116
|
+
any: () => new AnyValidator(),
|
|
117
|
+
literal: (literalValue) => new LiteralValidator(literalValue),
|
|
118
|
+
array: (itemValidator) => new ArrayValidator(itemValidator),
|
|
119
|
+
object: (shape) => new ObjectValidator(shape),
|
|
120
|
+
id: (tableName) => new IdValidator(tableName),
|
|
121
|
+
optional: (inner) => new OptionalValidator(inner)
|
|
122
|
+
};
|
|
123
|
+
function describeValidator(validator) {
|
|
124
|
+
switch (validator.kind) {
|
|
125
|
+
case "string":
|
|
126
|
+
case "number":
|
|
127
|
+
case "boolean":
|
|
128
|
+
case "null":
|
|
129
|
+
case "any": return { kind: validator.kind };
|
|
130
|
+
case "literal": return {
|
|
131
|
+
kind: "literal",
|
|
132
|
+
value: validator.literalValue
|
|
133
|
+
};
|
|
134
|
+
case "array": return {
|
|
135
|
+
kind: "array",
|
|
136
|
+
item: describeValidator(validator.itemValidator)
|
|
137
|
+
};
|
|
138
|
+
case "object": {
|
|
139
|
+
const objectValidator = validator;
|
|
140
|
+
return {
|
|
141
|
+
kind: "object",
|
|
142
|
+
shape: Object.fromEntries(Object.entries(objectValidator.shape).map(([key, nested]) => [key, describeValidator(nested)]))
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
case "id": return {
|
|
146
|
+
kind: "id",
|
|
147
|
+
tableName: validator.tableName
|
|
148
|
+
};
|
|
149
|
+
case "optional": return {
|
|
150
|
+
kind: "optional",
|
|
151
|
+
inner: describeValidator(validator.inner)
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
export { AnyValidator, ArrayValidator, BooleanValidator, IdValidator, LiteralValidator, NullValidator, NumberValidator, ObjectValidator, OptionalValidator, StringValidator, describeValidator, ensureObjectValidator, v };
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","names":[],"sources":["../../../../schema/src/validators.ts"],"sourcesContent":["export type ValidatorKind =\r\n | \"string\"\r\n | \"number\"\r\n | \"boolean\"\r\n | \"literal\"\r\n | \"array\"\r\n | \"object\"\r\n | \"id\"\r\n | \"optional\"\r\n | \"any\"\r\n | \"null\";\r\n\r\n/**\r\n * Validates unknown input at runtime and carries its parsed TypeScript type.\r\n *\r\n * Syncore uses validators for function arguments, return values, and table\r\n * definitions. Most apps create validators through {@link v} instead of\r\n * instantiating validator classes directly.\r\n */\r\nexport interface Validator<TValue> {\r\n readonly kind: ValidatorKind;\r\n\r\n /**\r\n * Parse and validate an unknown value.\r\n *\r\n * @param value - The value to validate.\r\n * @param path - A human-readable path used in validation errors.\r\n * @returns The parsed value when validation succeeds.\r\n */\r\n parse(value: unknown, path?: string): TValue;\r\n}\r\n\r\nexport type ValidatorDescription =\r\n | { kind: \"string\" }\r\n | { kind: \"number\" }\r\n | { kind: \"boolean\" }\r\n | { kind: \"null\" }\r\n | { kind: \"any\" }\r\n | { kind: \"literal\"; value: string | number | boolean | null }\r\n | { kind: \"array\"; item: ValidatorDescription }\r\n | { kind: \"object\"; shape: Record<string, ValidatorDescription> }\r\n | { kind: \"id\"; tableName: string }\r\n | { kind: \"optional\"; inner: ValidatorDescription };\r\n\r\nexport interface ObjectValidatorShape {\r\n [key: string]: Validator<unknown>;\r\n}\r\n\r\nexport class StringValidator implements Validator<string> {\r\n readonly kind = \"string\" as const;\r\n\r\n parse(value: unknown, path = \"value\"): string {\r\n if (typeof value !== \"string\") {\r\n throw new Error(`${path} must be a string.`);\r\n }\r\n return value;\r\n }\r\n}\r\n\r\nexport class NumberValidator implements Validator<number> {\r\n readonly kind = \"number\" as const;\r\n\r\n parse(value: unknown, path = \"value\"): number {\r\n if (typeof value !== \"number\" || Number.isNaN(value)) {\r\n throw new Error(`${path} must be a number.`);\r\n }\r\n return value;\r\n }\r\n}\r\n\r\nexport class BooleanValidator implements Validator<boolean> {\r\n readonly kind = \"boolean\" as const;\r\n\r\n parse(value: unknown, path = \"value\"): boolean {\r\n if (typeof value !== \"boolean\") {\r\n throw new Error(`${path} must be a boolean.`);\r\n }\r\n return value;\r\n }\r\n}\r\n\r\nexport class NullValidator implements Validator<null> {\r\n readonly kind = \"null\" as const;\r\n\r\n parse(value: unknown, path = \"value\"): null {\r\n if (value !== null) {\r\n throw new Error(`${path} must be null.`);\r\n }\r\n return null;\r\n }\r\n}\r\n\r\nexport class AnyValidator implements Validator<unknown> {\r\n readonly kind = \"any\" as const;\r\n\r\n parse(value: unknown): unknown {\r\n return value;\r\n }\r\n}\r\n\r\nexport class LiteralValidator<\r\n TValue extends string | number | boolean | null\r\n> implements Validator<TValue> {\r\n readonly kind = \"literal\" as const;\r\n\r\n constructor(public readonly literalValue: TValue) {}\r\n\r\n parse(value: unknown, path = \"value\"): TValue {\r\n if (value !== this.literalValue) {\r\n throw new Error(`${path} must equal ${String(this.literalValue)}.`);\r\n }\r\n return this.literalValue;\r\n }\r\n}\r\n\r\nexport class ArrayValidator<TItem> implements Validator<TItem[]> {\r\n readonly kind = \"array\" as const;\r\n\r\n constructor(public readonly itemValidator: Validator<TItem>) {}\r\n\r\n parse(value: unknown, path = \"value\"): TItem[] {\r\n if (!Array.isArray(value)) {\r\n throw new Error(`${path} must be an array.`);\r\n }\r\n return value.map((item, index) =>\r\n this.itemValidator.parse(item, `${path}[${index}]`)\r\n );\r\n }\r\n}\r\n\r\nexport class ObjectValidator<\r\n TShape extends ObjectValidatorShape\r\n> implements Validator<{ [TKey in keyof TShape]: Infer<TShape[TKey]> }> {\r\n readonly kind = \"object\" as const;\r\n\r\n constructor(public readonly shape: TShape) {}\r\n\r\n parse(\r\n value: unknown,\r\n path = \"value\"\r\n ): { [TKey in keyof TShape]: Infer<TShape[TKey]> } {\r\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\r\n throw new Error(`${path} must be an object.`);\r\n }\r\n\r\n const source = value as Record<string, unknown>;\r\n const parsed: Record<string, unknown> = {};\r\n\r\n for (const [key, validator] of Object.entries(this.shape)) {\r\n const optional =\r\n validator.kind === \"optional\" && source[key] === undefined;\r\n if (optional) {\r\n continue;\r\n }\r\n parsed[key] = validator.parse(source[key], `${path}.${key}`);\r\n }\r\n\r\n return parsed as { [TKey in keyof TShape]: Infer<TShape[TKey]> };\r\n }\r\n}\r\n\r\nexport class IdValidator<\r\n TTableName extends string\r\n> implements Validator<string> {\r\n readonly kind = \"id\" as const;\r\n\r\n constructor(public readonly tableName: TTableName) {}\r\n\r\n parse(value: unknown, path = \"value\"): string {\r\n if (typeof value !== \"string\" || value.length === 0) {\r\n throw new Error(`${path} must be a non-empty id string.`);\r\n }\r\n return value;\r\n }\r\n}\r\n\r\nexport class OptionalValidator<TValue> implements Validator<\r\n TValue | undefined\r\n> {\r\n readonly kind = \"optional\" as const;\r\n\r\n constructor(public readonly inner: Validator<TValue>) {}\r\n\r\n parse(value: unknown, path = \"value\"): TValue | undefined {\r\n if (value === undefined) {\r\n return undefined;\r\n }\r\n return this.inner.parse(value, path);\r\n }\r\n}\r\n\r\nexport type Infer<TValidator> =\r\n TValidator extends Validator<infer TValue> ? TValue : never;\r\n\r\nexport type ValidatorMap = Record<string, Validator<unknown>>;\r\n\r\n/**\r\n * The public validator builder API.\r\n *\r\n * Hover each property in your editor to see what it validates and how to use it.\r\n */\r\nexport interface ValidatorBuilderApi {\r\n /**\r\n * Validate a string value.\r\n *\r\n * @returns A validator that accepts JavaScript strings.\r\n */\r\n string(): StringValidator;\r\n\r\n /**\r\n * Validate a number value.\r\n *\r\n * @returns A validator that accepts finite JavaScript numbers.\r\n */\r\n number(): NumberValidator;\r\n\r\n /**\r\n * Validate a boolean value.\r\n *\r\n * @returns A validator that accepts `true` and `false`.\r\n */\r\n boolean(): BooleanValidator;\r\n\r\n /**\r\n * Validate the literal value `null`.\r\n *\r\n * @returns A validator that only accepts `null`.\r\n */\r\n null(): NullValidator;\r\n\r\n /**\r\n * Accept any value without validation.\r\n *\r\n * Use this sparingly for escape hatches when you do not want Syncore to\r\n * enforce a more specific runtime shape.\r\n */\r\n any(): AnyValidator;\r\n\r\n /**\r\n * Validate a single literal value.\r\n *\r\n * @param literalValue - The exact value that must be provided.\r\n * @returns A validator that only accepts that one value.\r\n */\r\n literal<TValue extends string | number | boolean | null>(\r\n literalValue: TValue\r\n ): LiteralValidator<TValue>;\r\n\r\n /**\r\n * Validate an array whose items all use the same validator.\r\n *\r\n * @param itemValidator - The validator for each item in the array.\r\n * @returns A validator for arrays of the provided item type.\r\n */\r\n array<TItem>(itemValidator: Validator<TItem>): ArrayValidator<TItem>;\r\n\r\n /**\r\n * Validate an object with a fixed property shape.\r\n *\r\n * @param shape - The validators for each property on the object.\r\n * @returns A validator for objects matching that shape.\r\n */\r\n object<TShape extends ObjectValidatorShape>(\r\n shape: TShape\r\n ): ObjectValidator<TShape>;\r\n\r\n /**\r\n * Validate an identifier string that points at a table.\r\n *\r\n * Use this for document ids that come from Syncore tables.\r\n *\r\n * @param tableName - The name of the referenced table.\r\n * @returns A validator for ids belonging to that table.\r\n */\r\n id<TTableName extends string>(tableName: TTableName): IdValidator<TTableName>;\r\n\r\n /**\r\n * Make another validator optional.\r\n *\r\n * @param inner - The validator for the defined case.\r\n * @returns A validator that accepts `undefined` or the inner value.\r\n */\r\n optional<TValue>(inner: Validator<TValue>): OptionalValidator<TValue>;\r\n}\r\n\r\nfunction isValidator(\r\n value: Validator<unknown> | ValidatorMap\r\n): value is Validator<unknown> {\r\n return typeof (value as Validator<unknown>).parse === \"function\";\r\n}\r\n\r\nexport function ensureObjectValidator(\r\n value: Validator<unknown> | ValidatorMap\r\n): Validator<unknown> {\r\n if (isValidator(value)) {\r\n return value;\r\n }\r\n return new ObjectValidator(value);\r\n}\r\n\r\n/**\r\n * Build runtime validators for schemas, function args, and return values.\r\n *\r\n * @example\r\n * ```ts\r\n * defineTable({\r\n * text: v.string(),\r\n * done: v.boolean(),\r\n * ownerId: v.optional(v.id(\"users\"))\r\n * });\r\n * ```\r\n */\r\nexport const v: ValidatorBuilderApi = {\r\n string: () => new StringValidator(),\r\n number: () => new NumberValidator(),\r\n boolean: () => new BooleanValidator(),\r\n null: () => new NullValidator(),\r\n any: () => new AnyValidator(),\r\n literal: <TValue extends string | number | boolean | null>(\r\n literalValue: TValue\r\n ) => new LiteralValidator(literalValue),\r\n array: <TItem>(itemValidator: Validator<TItem>) =>\r\n new ArrayValidator(itemValidator),\r\n object: <TShape extends ObjectValidatorShape>(shape: TShape) =>\r\n new ObjectValidator(shape),\r\n id: <TTableName extends string>(tableName: TTableName) =>\r\n new IdValidator(tableName),\r\n optional: <TValue>(inner: Validator<TValue>) => new OptionalValidator(inner)\r\n};\r\n\r\nexport function describeValidator(\r\n validator: Validator<unknown>\r\n): ValidatorDescription {\r\n switch (validator.kind) {\r\n case \"string\":\r\n case \"number\":\r\n case \"boolean\":\r\n case \"null\":\r\n case \"any\":\r\n return { kind: validator.kind };\r\n case \"literal\":\r\n return {\r\n kind: \"literal\",\r\n value: (validator as LiteralValidator<string | number | boolean | null>)\r\n .literalValue\r\n };\r\n case \"array\":\r\n return {\r\n kind: \"array\",\r\n item: describeValidator(\r\n (validator as ArrayValidator<unknown>).itemValidator\r\n )\r\n };\r\n case \"object\": {\r\n const objectValidator =\r\n validator as ObjectValidator<ObjectValidatorShape>;\r\n return {\r\n kind: \"object\",\r\n shape: Object.fromEntries(\r\n Object.entries(objectValidator.shape).map(([key, nested]) => [\r\n key,\r\n describeValidator(nested)\r\n ])\r\n )\r\n };\r\n }\r\n case \"id\":\r\n return {\r\n kind: \"id\",\r\n tableName: (validator as IdValidator<string>).tableName\r\n };\r\n case \"optional\":\r\n return {\r\n kind: \"optional\",\r\n inner: describeValidator(\r\n (validator as OptionalValidator<unknown>).inner\r\n )\r\n };\r\n }\r\n}\r\n"],"mappings":"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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FunctionArgs, FunctionReference, FunctionResult } from "../../core/src/runtime/functions.js";
|
|
2
|
+
import { SyncoreClient } from "../../core/src/runtime/runtime.js";
|
|
3
|
+
import { Readable } from "svelte/store";
|
|
4
|
+
|
|
5
|
+
//#region ../svelte/src/index.d.ts
|
|
6
|
+
type OptionalArgsTuple<TArgs> = Record<never, never> extends TArgs ? [args?: TArgs] : [args: TArgs];
|
|
7
|
+
/**
|
|
8
|
+
* The observable state exposed by a Syncore-backed Svelte query store.
|
|
9
|
+
*/
|
|
10
|
+
interface SyncoreQueryStoreState<TResult> {
|
|
11
|
+
/** The latest local result for the watched query. */
|
|
12
|
+
data: TResult | undefined;
|
|
13
|
+
/** The latest local error for the watched query, if any. */
|
|
14
|
+
error: Error | undefined;
|
|
15
|
+
/** The current watch lifecycle status. */
|
|
16
|
+
status: "loading" | "ready" | "error";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Store a Syncore client in the current Svelte component context.
|
|
20
|
+
*/
|
|
21
|
+
declare function setSyncoreClient(client: SyncoreClient): SyncoreClient;
|
|
22
|
+
/**
|
|
23
|
+
* Read the active Syncore client from the current Svelte component context.
|
|
24
|
+
*/
|
|
25
|
+
declare function getSyncoreClient(): SyncoreClient;
|
|
26
|
+
/**
|
|
27
|
+
* Create a readable Svelte store backed by a reactive Syncore query.
|
|
28
|
+
*/
|
|
29
|
+
declare function createQueryStore<TReference extends FunctionReference<"query">>(reference: TReference, ...args: OptionalArgsTuple<FunctionArgs<TReference>>): Readable<SyncoreQueryStoreState<FunctionResult<TReference>>>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a readable Svelte store backed by a reactive Syncore query.
|
|
32
|
+
*/
|
|
33
|
+
declare function createClientQueryStore<TReference extends FunctionReference<"query">>(client: SyncoreClient, reference: TReference, ...args: OptionalArgsTuple<FunctionArgs<TReference>>): Readable<SyncoreQueryStoreState<FunctionResult<TReference>>>;
|
|
34
|
+
/**
|
|
35
|
+
* Create a function that executes a Syncore mutation.
|
|
36
|
+
*/
|
|
37
|
+
declare function createMutation<TReference extends FunctionReference<"mutation">>(reference: TReference): (...args: OptionalArgsTuple<FunctionArgs<TReference>>) => Promise<FunctionResult<TReference>>;
|
|
38
|
+
/**
|
|
39
|
+
* Create a function that executes a Syncore action.
|
|
40
|
+
*/
|
|
41
|
+
declare function createAction<TReference extends FunctionReference<"action">>(reference: TReference): (...args: OptionalArgsTuple<FunctionArgs<TReference>>) => Promise<FunctionResult<TReference>>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { OptionalArgsTuple, SyncoreQueryStoreState, createAction, createClientQueryStore, createMutation, createQueryStore, getSyncoreClient, setSyncoreClient };
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../svelte/src/index.ts"],"mappings":";;;;;KAUY,iBAAA,UACV,MAAA,uBAA6B,KAAA,IAAS,IAAA,GAAO,KAAA,KAAU,IAAA,EAAM,KAAA;;;AAD/D;UAMiB,sBAAA;EANY;EAQ3B,IAAA,EAAM,OAAA;EAPuB;EAU7B,KAAA,EAAO,KAAA;EAVsD;EAa7D,MAAA;AAAA;;;;iBAQc,gBAAA,CAAiB,MAAA,EAAQ,aAAA,GAAgB,aAAA;;;;iBAQzC,gBAAA,CAAA,GAAoB,aAAA;;AAxBpC;;iBAqCgB,gBAAA,oBAAoC,iBAAA,UAAA,CAClD,SAAA,EAAW,UAAA,KACR,IAAA,EAAM,iBAAA,CAAkB,YAAA,CAAa,UAAA,KACvC,QAAA,CAAS,sBAAA,CAAuB,cAAA,CAAe,UAAA;;;;iBAOlC,sBAAA,oBACK,iBAAA,UAAA,CAEnB,MAAA,EAAQ,aAAA,EACR,SAAA,EAAW,UAAA,KACR,IAAA,EAAM,iBAAA,CAAkB,YAAA,CAAa,UAAA,KACvC,QAAA,CAAS,sBAAA,CAAuB,cAAA,CAAe,UAAA;;;;iBAelC,cAAA,oBACK,iBAAA,aAAA,CAEnB,SAAA,EAAW,UAAA,OAER,IAAA,EAAM,iBAAA,CAAkB,YAAA,CAAa,UAAA,OACrC,OAAA,CAAQ,cAAA,CAAe,UAAA;;AA1D5B;;iBAqEgB,YAAA,oBAAgC,iBAAA,WAAA,CAC9C,SAAA,EAAW,UAAA,OAER,IAAA,EAAM,iBAAA,CAAkB,YAAA,CAAa,UAAA,OACrC,OAAA,CAAQ,cAAA,CAAe,UAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { readable } from "svelte/store";
|
|
2
|
+
import { getContext, setContext } from "svelte";
|
|
3
|
+
//#region ../svelte/src/index.ts
|
|
4
|
+
const SYNCORE_CLIENT_CONTEXT = Symbol("syncore.client");
|
|
5
|
+
/**
|
|
6
|
+
* Store a Syncore client in the current Svelte component context.
|
|
7
|
+
*/
|
|
8
|
+
function setSyncoreClient(client) {
|
|
9
|
+
setContext(SYNCORE_CLIENT_CONTEXT, client);
|
|
10
|
+
return client;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Read the active Syncore client from the current Svelte component context.
|
|
14
|
+
*/
|
|
15
|
+
function getSyncoreClient() {
|
|
16
|
+
const client = getContext(SYNCORE_CLIENT_CONTEXT);
|
|
17
|
+
if (!client) throw new Error("Syncore client is missing from the Svelte component context.");
|
|
18
|
+
return client;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a readable Svelte store backed by a reactive Syncore query.
|
|
22
|
+
*/
|
|
23
|
+
function createQueryStore(reference, ...args) {
|
|
24
|
+
return createClientQueryStore(getSyncoreClient(), reference, ...args);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a readable Svelte store backed by a reactive Syncore query.
|
|
28
|
+
*/
|
|
29
|
+
function createClientQueryStore(client, reference, ...args) {
|
|
30
|
+
return readable({
|
|
31
|
+
data: void 0,
|
|
32
|
+
error: void 0,
|
|
33
|
+
status: "loading"
|
|
34
|
+
}, createQueryStoreStart(client, reference, normalizeOptionalArgs(args)));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a function that executes a Syncore mutation.
|
|
38
|
+
*/
|
|
39
|
+
function createMutation(reference) {
|
|
40
|
+
const client = getSyncoreClient();
|
|
41
|
+
return (...args) => client.mutation(reference, normalizeOptionalArgs(args));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a function that executes a Syncore action.
|
|
45
|
+
*/
|
|
46
|
+
function createAction(reference) {
|
|
47
|
+
const client = getSyncoreClient();
|
|
48
|
+
return (...args) => client.action(reference, normalizeOptionalArgs(args));
|
|
49
|
+
}
|
|
50
|
+
function createQueryStoreStart(client, reference, args) {
|
|
51
|
+
return (set) => {
|
|
52
|
+
const watch = client.watchQuery(reference, args);
|
|
53
|
+
const sync = () => {
|
|
54
|
+
const error = watch.localQueryError();
|
|
55
|
+
set({
|
|
56
|
+
data: watch.localQueryResult(),
|
|
57
|
+
error,
|
|
58
|
+
status: error ? "error" : "ready"
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
sync();
|
|
62
|
+
const unsubscribe = watch.onUpdate(sync);
|
|
63
|
+
return () => {
|
|
64
|
+
unsubscribe();
|
|
65
|
+
watch.dispose?.();
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function normalizeOptionalArgs(args) {
|
|
70
|
+
return args[0] ?? {};
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { createAction, createClientQueryStore, createMutation, createQueryStore, getSyncoreClient, setSyncoreClient };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../svelte/src/index.ts"],"sourcesContent":["import { type Readable, type StartStopNotifier, readable } from \"svelte/store\";\nimport { getContext, setContext } from \"svelte\";\nimport type {\n FunctionArgs,\n FunctionReference,\n FunctionResult,\n SyncoreClient,\n SyncoreWatch\n} from \"@syncore/core\";\n\nexport type OptionalArgsTuple<TArgs> =\n Record<never, never> extends TArgs ? [args?: TArgs] : [args: TArgs];\n\n/**\n * The observable state exposed by a Syncore-backed Svelte query store.\n */\nexport interface SyncoreQueryStoreState<TResult> {\n /** The latest local result for the watched query. */\n data: TResult | undefined;\n\n /** The latest local error for the watched query, if any. */\n error: Error | undefined;\n\n /** The current watch lifecycle status. */\n status: \"loading\" | \"ready\" | \"error\";\n}\n\nconst SYNCORE_CLIENT_CONTEXT = Symbol(\"syncore.client\");\n\n/**\n * Store a Syncore client in the current Svelte component context.\n */\nexport function setSyncoreClient(client: SyncoreClient): SyncoreClient {\n setContext(SYNCORE_CLIENT_CONTEXT, client);\n return client;\n}\n\n/**\n * Read the active Syncore client from the current Svelte component context.\n */\nexport function getSyncoreClient(): SyncoreClient {\n const client = getContext<SyncoreClient | undefined>(SYNCORE_CLIENT_CONTEXT);\n if (!client) {\n throw new Error(\n \"Syncore client is missing from the Svelte component context.\"\n );\n }\n return client;\n}\n\n/**\n * Create a readable Svelte store backed by a reactive Syncore query.\n */\nexport function createQueryStore<TReference extends FunctionReference<\"query\">>(\n reference: TReference,\n ...args: OptionalArgsTuple<FunctionArgs<TReference>>\n): Readable<SyncoreQueryStoreState<FunctionResult<TReference>>> {\n return createClientQueryStore(getSyncoreClient(), reference, ...args);\n}\n\n/**\n * Create a readable Svelte store backed by a reactive Syncore query.\n */\nexport function createClientQueryStore<\n TReference extends FunctionReference<\"query\">\n>(\n client: SyncoreClient,\n reference: TReference,\n ...args: OptionalArgsTuple<FunctionArgs<TReference>>\n): Readable<SyncoreQueryStoreState<FunctionResult<TReference>>> {\n const normalizedArgs = normalizeOptionalArgs(args);\n return readable<SyncoreQueryStoreState<FunctionResult<TReference>>>(\n {\n data: undefined,\n error: undefined,\n status: \"loading\"\n },\n createQueryStoreStart(client, reference, normalizedArgs)\n );\n}\n\n/**\n * Create a function that executes a Syncore mutation.\n */\nexport function createMutation<\n TReference extends FunctionReference<\"mutation\">\n>(\n reference: TReference\n): (\n ...args: OptionalArgsTuple<FunctionArgs<TReference>>\n) => Promise<FunctionResult<TReference>> {\n const client = getSyncoreClient();\n return (...args) =>\n client.mutation(reference, normalizeOptionalArgs(args)) as Promise<\n FunctionResult<TReference>\n >;\n}\n\n/**\n * Create a function that executes a Syncore action.\n */\nexport function createAction<TReference extends FunctionReference<\"action\">>(\n reference: TReference\n): (\n ...args: OptionalArgsTuple<FunctionArgs<TReference>>\n) => Promise<FunctionResult<TReference>> {\n const client = getSyncoreClient();\n return (...args) =>\n client.action(reference, normalizeOptionalArgs(args)) as Promise<\n FunctionResult<TReference>\n >;\n}\n\nfunction createQueryStoreStart<TReference extends FunctionReference<\"query\">>(\n client: SyncoreClient,\n reference: TReference,\n args: FunctionArgs<TReference>\n): StartStopNotifier<SyncoreQueryStoreState<FunctionResult<TReference>>> {\n return (\n set: (value: SyncoreQueryStoreState<FunctionResult<TReference>>) => void\n ) => {\n const watch = client.watchQuery(reference, args) as SyncoreWatch<\n FunctionResult<TReference>\n >;\n const sync = () => {\n const error = watch.localQueryError();\n set({\n data: watch.localQueryResult(),\n error,\n status: error ? \"error\" : \"ready\"\n });\n };\n sync();\n const unsubscribe = watch.onUpdate(sync);\n return () => {\n unsubscribe();\n watch.dispose?.();\n };\n };\n}\n\nfunction normalizeOptionalArgs<TArgs>(\n args: [] | [TArgs] | readonly unknown[]\n): TArgs {\n return (args[0] ?? {}) as TArgs;\n}\n"],"mappings":";;;AA2BA,MAAM,yBAAyB,OAAO,iBAAiB;;;;AAKvD,SAAgB,iBAAiB,QAAsC;AACrE,YAAW,wBAAwB,OAAO;AAC1C,QAAO;;;;;AAMT,SAAgB,mBAAkC;CAChD,MAAM,SAAS,WAAsC,uBAAuB;AAC5E,KAAI,CAAC,OACH,OAAM,IAAI,MACR,+DACD;AAEH,QAAO;;;;;AAMT,SAAgB,iBACd,WACA,GAAG,MAC2D;AAC9D,QAAO,uBAAuB,kBAAkB,EAAE,WAAW,GAAG,KAAK;;;;;AAMvE,SAAgB,uBAGd,QACA,WACA,GAAG,MAC2D;AAE9D,QAAO,SACL;EACE,MAAM,KAAA;EACN,OAAO,KAAA;EACP,QAAQ;EACT,EACD,sBAAsB,QAAQ,WAPT,sBAAsB,KAAK,CAOQ,CACzD;;;;;AAMH,SAAgB,eAGd,WAGuC;CACvC,MAAM,SAAS,kBAAkB;AACjC,SAAQ,GAAG,SACT,OAAO,SAAS,WAAW,sBAAsB,KAAK,CAAC;;;;;AAQ3D,SAAgB,aACd,WAGuC;CACvC,MAAM,SAAS,kBAAkB;AACjC,SAAQ,GAAG,SACT,OAAO,OAAO,WAAW,sBAAsB,KAAK,CAAC;;AAKzD,SAAS,sBACP,QACA,WACA,MACuE;AACvE,SACE,QACG;EACH,MAAM,QAAQ,OAAO,WAAW,WAAW,KAAK;EAGhD,MAAM,aAAa;GACjB,MAAM,QAAQ,MAAM,iBAAiB;AACrC,OAAI;IACF,MAAM,MAAM,kBAAkB;IAC9B;IACA,QAAQ,QAAQ,UAAU;IAC3B,CAAC;;AAEJ,QAAM;EACN,MAAM,cAAc,MAAM,SAAS,KAAK;AACxC,eAAa;AACX,gBAAa;AACb,SAAM,WAAW;;;;AAKvB,SAAS,sBACP,MACO;AACP,QAAQ,KAAK,MAAM,EAAE"}
|
package/dist/svelte.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { OptionalArgsTuple, SyncoreQueryStoreState, createAction, createClientQueryStore, createMutation, createQueryStore, getSyncoreClient, setSyncoreClient } from "./svelte/src/index.js";
|
|
2
|
+
export { OptionalArgsTuple, SyncoreQueryStoreState, createAction, createClientQueryStore, createMutation, createQueryStore, getSyncoreClient, setSyncoreClient };
|
package/dist/svelte.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "syncorejs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local-first reactive backend toolkit for offline apps",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"bin": {
|
|
15
|
+
"syncorejs": "./dist/cli.js"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/JPSAUD501/Syncore.git",
|
|
20
|
+
"directory": "packages/syncore"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/JPSAUD501/Syncore#readme",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/JPSAUD501/Syncore/issues"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"provenance": true
|
|
29
|
+
},
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"default": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./cli": {
|
|
37
|
+
"default": "./dist/cli.js",
|
|
38
|
+
"types": "./dist/cli.d.ts",
|
|
39
|
+
"import": "./dist/cli.js"
|
|
40
|
+
},
|
|
41
|
+
"./browser": {
|
|
42
|
+
"default": "./dist/browser.js",
|
|
43
|
+
"types": "./dist/browser.d.ts",
|
|
44
|
+
"import": "./dist/browser.js"
|
|
45
|
+
},
|
|
46
|
+
"./browser/react": {
|
|
47
|
+
"default": "./dist/browser-react.js",
|
|
48
|
+
"types": "./dist/browser-react.d.ts",
|
|
49
|
+
"import": "./dist/browser-react.js"
|
|
50
|
+
},
|
|
51
|
+
"./react": {
|
|
52
|
+
"default": "./dist/react.js",
|
|
53
|
+
"types": "./dist/react.d.ts",
|
|
54
|
+
"import": "./dist/react.js"
|
|
55
|
+
},
|
|
56
|
+
"./svelte": {
|
|
57
|
+
"default": "./dist/svelte.js",
|
|
58
|
+
"types": "./dist/svelte.d.ts",
|
|
59
|
+
"import": "./dist/svelte.js"
|
|
60
|
+
},
|
|
61
|
+
"./expo": {
|
|
62
|
+
"default": "./dist/expo.js",
|
|
63
|
+
"types": "./dist/expo.d.ts",
|
|
64
|
+
"import": "./dist/expo.js"
|
|
65
|
+
},
|
|
66
|
+
"./expo/react": {
|
|
67
|
+
"default": "./dist/expo-react.js",
|
|
68
|
+
"types": "./dist/expo-react.d.ts",
|
|
69
|
+
"import": "./dist/expo-react.js"
|
|
70
|
+
},
|
|
71
|
+
"./node": {
|
|
72
|
+
"default": "./dist/node.js",
|
|
73
|
+
"types": "./dist/node.d.ts",
|
|
74
|
+
"import": "./dist/node.js"
|
|
75
|
+
},
|
|
76
|
+
"./node/ipc": {
|
|
77
|
+
"default": "./dist/node-ipc.js",
|
|
78
|
+
"types": "./dist/node-ipc.d.ts",
|
|
79
|
+
"import": "./dist/node-ipc.js"
|
|
80
|
+
},
|
|
81
|
+
"./node/ipc/react": {
|
|
82
|
+
"default": "./dist/node-ipc-react.js",
|
|
83
|
+
"types": "./dist/node-ipc-react.d.ts",
|
|
84
|
+
"import": "./dist/node-ipc-react.js"
|
|
85
|
+
},
|
|
86
|
+
"./next": {
|
|
87
|
+
"default": "./dist/next.js",
|
|
88
|
+
"types": "./dist/next.d.ts",
|
|
89
|
+
"import": "./dist/next.js"
|
|
90
|
+
},
|
|
91
|
+
"./next/config": {
|
|
92
|
+
"default": "./dist/next-config.js",
|
|
93
|
+
"types": "./dist/next-config.d.ts",
|
|
94
|
+
"import": "./dist/next-config.js"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"scripts": {
|
|
98
|
+
"build": "tsdown --config tsdown.config.ts && tsx ../../scripts/vendor-syncore-internals.ts",
|
|
99
|
+
"build:deps": "bun run --filter @syncore/core build && bun run --filter @syncore/schema build && bun run --filter @syncore/devtools-protocol build && bun run --filter @syncore/react build && bun run --filter @syncore/platform-web build && bun run --filter @syncore/platform-node build && bun run --filter @syncore/platform-expo build && bun run --filter @syncore/next build && bun run --filter @syncore/svelte build",
|
|
100
|
+
"build:standalone": "bun run build:deps && bun run build",
|
|
101
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
102
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
103
|
+
"test": "vitest run --passWithNoTests",
|
|
104
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
105
|
+
},
|
|
106
|
+
"dependencies": {
|
|
107
|
+
"commander": "^13.1.0",
|
|
108
|
+
"date-fns-tz": "^3.2.0",
|
|
109
|
+
"sql.js": "^1.14.1",
|
|
110
|
+
"tsx": "^4.19.3",
|
|
111
|
+
"ws": "^8.18.0"
|
|
112
|
+
},
|
|
113
|
+
"peerDependencies": {
|
|
114
|
+
"expo-file-system": "^55.0.10",
|
|
115
|
+
"expo-sqlite": "^55.0.10",
|
|
116
|
+
"next": "^15.0.0",
|
|
117
|
+
"react": "^18.3.0 || ^19.0.0",
|
|
118
|
+
"react-dom": "^18.3.0 || ^19.0.0",
|
|
119
|
+
"svelte": "^5.0.0"
|
|
120
|
+
},
|
|
121
|
+
"peerDependenciesMeta": {
|
|
122
|
+
"expo-file-system": {
|
|
123
|
+
"optional": true
|
|
124
|
+
},
|
|
125
|
+
"expo-sqlite": {
|
|
126
|
+
"optional": true
|
|
127
|
+
},
|
|
128
|
+
"next": {
|
|
129
|
+
"optional": true
|
|
130
|
+
},
|
|
131
|
+
"react": {
|
|
132
|
+
"optional": true
|
|
133
|
+
},
|
|
134
|
+
"react-dom": {
|
|
135
|
+
"optional": true
|
|
136
|
+
},
|
|
137
|
+
"svelte": {
|
|
138
|
+
"optional": true
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"devDependencies": {
|
|
142
|
+
"@syncore/core": "workspace:*",
|
|
143
|
+
"@syncore/devtools-protocol": "workspace:*",
|
|
144
|
+
"@syncore/next": "workspace:*",
|
|
145
|
+
"@syncore/platform-expo": "workspace:*",
|
|
146
|
+
"@syncore/platform-node": "workspace:*",
|
|
147
|
+
"@syncore/platform-web": "workspace:*",
|
|
148
|
+
"@syncore/react": "workspace:*",
|
|
149
|
+
"@syncore/schema": "workspace:*",
|
|
150
|
+
"@syncore/svelte": "workspace:*"
|
|
151
|
+
}
|
|
152
|
+
}
|