@sylphx/lens-solid 2.3.13 → 2.3.14
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/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +88 -496
- package/package.json +3 -3
- package/src/index.ts +0 -17
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,5 @@
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
export { createClient, type MutationEndpoint, type MutationPrimitiveOptions, type MutationPrimitiveResult, type QueryEndpoint, type QueryPrimitiveOptions, type QueryPrimitiveResult, type TypedClient, } from "./create.js";
|
|
28
|
-
export { LensProvider, type LensProviderProps, useLensClient } from "./context.js";
|
|
29
28
|
export { type CreateLazyQueryResult, type CreateMutationResult, type CreateQueryOptions, type CreateQueryResult, createLazyQuery, createMutation, createQuery, type MutationFn, type QueryInput, } from "./primitives.js";
|
|
30
29
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EACN,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,WAAW,GAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,eAAe,EACf,cAAc,EACd,WAAW,EACX,KAAK,UAAU,EACf,KAAK,UAAU,GACf,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,465 +3,9 @@ var DSL_MARKER = Symbol("reify");
|
|
|
3
3
|
// ../../node_modules/.bun/@sylphx+reify-core@0.1.2/node_modules/@sylphx/reify-core/dist/evaluator.js
|
|
4
4
|
var plugins = new Map;
|
|
5
5
|
// ../core/dist/index.js
|
|
6
|
-
|
|
7
|
-
_nullable = false;
|
|
8
|
-
_optional = false;
|
|
9
|
-
_default;
|
|
10
|
-
_resolutionMode = "exposed";
|
|
11
|
-
_resolver;
|
|
12
|
-
_subscriptionResolver;
|
|
13
|
-
nullable() {
|
|
14
|
-
const clone = Object.create(this);
|
|
15
|
-
clone._nullable = true;
|
|
16
|
-
return clone;
|
|
17
|
-
}
|
|
18
|
-
optional() {
|
|
19
|
-
const clone = Object.create(this);
|
|
20
|
-
clone._optional = true;
|
|
21
|
-
return clone;
|
|
22
|
-
}
|
|
23
|
-
default(value) {
|
|
24
|
-
const clone = Object.create(this);
|
|
25
|
-
clone._default = value;
|
|
26
|
-
return clone;
|
|
27
|
-
}
|
|
28
|
-
isNullable() {
|
|
29
|
-
return this._nullable;
|
|
30
|
-
}
|
|
31
|
-
isOptional() {
|
|
32
|
-
return this._optional;
|
|
33
|
-
}
|
|
34
|
-
getDefault() {
|
|
35
|
-
return this._default;
|
|
36
|
-
}
|
|
37
|
-
serialize(value) {
|
|
38
|
-
return value;
|
|
39
|
-
}
|
|
40
|
-
deserialize(value) {
|
|
41
|
-
return value;
|
|
42
|
-
}
|
|
43
|
-
resolve(fn) {
|
|
44
|
-
const clone = Object.create(this);
|
|
45
|
-
clone._resolutionMode = "resolve";
|
|
46
|
-
clone._resolver = fn;
|
|
47
|
-
return clone;
|
|
48
|
-
}
|
|
49
|
-
subscribe(fn) {
|
|
50
|
-
const clone = Object.create(this);
|
|
51
|
-
clone._resolutionMode = "subscribe";
|
|
52
|
-
clone._subscriptionResolver = fn;
|
|
53
|
-
return clone;
|
|
54
|
-
}
|
|
55
|
-
hasResolver() {
|
|
56
|
-
return this._resolutionMode === "resolve" && this._resolver !== undefined;
|
|
57
|
-
}
|
|
58
|
-
hasSubscription() {
|
|
59
|
-
return this._resolutionMode === "subscribe" && this._subscriptionResolver !== undefined;
|
|
60
|
-
}
|
|
61
|
-
getResolutionMode() {
|
|
62
|
-
return this._resolutionMode;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
class IdType extends FieldType {
|
|
67
|
-
_type = "id";
|
|
68
|
-
_tsType;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
class StringType extends FieldType {
|
|
72
|
-
_type = "string";
|
|
73
|
-
_tsType;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
class IntType extends FieldType {
|
|
77
|
-
_type = "int";
|
|
78
|
-
_tsType;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
class FloatType extends FieldType {
|
|
82
|
-
_type = "float";
|
|
83
|
-
_tsType;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
class BooleanType extends FieldType {
|
|
87
|
-
_type = "boolean";
|
|
88
|
-
_tsType;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
class DateTimeType extends FieldType {
|
|
92
|
-
_type = "datetime";
|
|
93
|
-
_tsType;
|
|
94
|
-
serialize(value) {
|
|
95
|
-
if (!(value instanceof Date)) {
|
|
96
|
-
throw new Error(`Expected Date instance, got ${typeof value}`);
|
|
97
|
-
}
|
|
98
|
-
return value.toISOString();
|
|
99
|
-
}
|
|
100
|
-
deserialize(value) {
|
|
101
|
-
if (typeof value !== "string") {
|
|
102
|
-
throw new Error(`Expected string, got ${typeof value}`);
|
|
103
|
-
}
|
|
104
|
-
const date = new Date(value);
|
|
105
|
-
if (Number.isNaN(date.getTime())) {
|
|
106
|
-
throw new Error(`Invalid date string: ${value}`);
|
|
107
|
-
}
|
|
108
|
-
return date;
|
|
109
|
-
}
|
|
110
|
-
validate(value) {
|
|
111
|
-
return value instanceof Date && !Number.isNaN(value.getTime());
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
class TimestampType extends FieldType {
|
|
116
|
-
_type = "timestamp";
|
|
117
|
-
_tsType;
|
|
118
|
-
validate(value) {
|
|
119
|
-
return typeof value === "number" && !Number.isNaN(value) && Number.isFinite(value);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
class DecimalType extends FieldType {
|
|
124
|
-
_type = "decimal";
|
|
125
|
-
_tsType;
|
|
126
|
-
serialize(value) {
|
|
127
|
-
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
128
|
-
throw new Error(`Expected number, got ${typeof value}`);
|
|
129
|
-
}
|
|
130
|
-
return value.toString();
|
|
131
|
-
}
|
|
132
|
-
deserialize(value) {
|
|
133
|
-
if (typeof value !== "string") {
|
|
134
|
-
throw new Error(`Expected string, got ${typeof value}`);
|
|
135
|
-
}
|
|
136
|
-
const num = Number.parseFloat(value);
|
|
137
|
-
if (Number.isNaN(num)) {
|
|
138
|
-
throw new Error(`Invalid decimal string: ${value}`);
|
|
139
|
-
}
|
|
140
|
-
return num;
|
|
141
|
-
}
|
|
142
|
-
validate(value) {
|
|
143
|
-
return typeof value === "number" && !Number.isNaN(value) && Number.isFinite(value);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
class DateType extends FieldType {
|
|
148
|
-
_type = "date";
|
|
149
|
-
_tsType;
|
|
150
|
-
serialize(value) {
|
|
151
|
-
if (!(value instanceof Date)) {
|
|
152
|
-
throw new Error(`Expected Date instance, got ${typeof value}`);
|
|
153
|
-
}
|
|
154
|
-
return value.toISOString().split("T")[0];
|
|
155
|
-
}
|
|
156
|
-
deserialize(value) {
|
|
157
|
-
if (typeof value !== "string") {
|
|
158
|
-
throw new Error(`Expected string, got ${typeof value}`);
|
|
159
|
-
}
|
|
160
|
-
const date = new Date(`${value}T00:00:00.000Z`);
|
|
161
|
-
if (Number.isNaN(date.getTime())) {
|
|
162
|
-
throw new Error(`Invalid date string: ${value}`);
|
|
163
|
-
}
|
|
164
|
-
return date;
|
|
165
|
-
}
|
|
166
|
-
validate(value) {
|
|
167
|
-
return value instanceof Date && !Number.isNaN(value.getTime());
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
class BigIntType extends FieldType {
|
|
172
|
-
_type = "bigint";
|
|
173
|
-
_tsType;
|
|
174
|
-
serialize(value) {
|
|
175
|
-
if (typeof value !== "bigint") {
|
|
176
|
-
throw new Error(`Expected bigint, got ${typeof value}`);
|
|
177
|
-
}
|
|
178
|
-
return value.toString();
|
|
179
|
-
}
|
|
180
|
-
deserialize(value) {
|
|
181
|
-
if (typeof value !== "string") {
|
|
182
|
-
throw new Error(`Expected string, got ${typeof value}`);
|
|
183
|
-
}
|
|
184
|
-
try {
|
|
185
|
-
return BigInt(value);
|
|
186
|
-
} catch {
|
|
187
|
-
throw new Error(`Invalid bigint string: ${value}`);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
validate(value) {
|
|
191
|
-
return typeof value === "bigint";
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
class BytesType extends FieldType {
|
|
196
|
-
_type = "bytes";
|
|
197
|
-
_tsType;
|
|
198
|
-
serialize(value) {
|
|
199
|
-
if (!(value instanceof Uint8Array)) {
|
|
200
|
-
throw new Error(`Expected Uint8Array, got ${typeof value}`);
|
|
201
|
-
}
|
|
202
|
-
if (typeof btoa === "function") {
|
|
203
|
-
return btoa(String.fromCharCode(...value));
|
|
204
|
-
}
|
|
205
|
-
return Buffer.from(value).toString("base64");
|
|
206
|
-
}
|
|
207
|
-
deserialize(value) {
|
|
208
|
-
if (typeof value !== "string") {
|
|
209
|
-
throw new Error(`Expected string, got ${typeof value}`);
|
|
210
|
-
}
|
|
211
|
-
if (typeof atob === "function") {
|
|
212
|
-
const binary = atob(value);
|
|
213
|
-
const bytes = new Uint8Array(binary.length);
|
|
214
|
-
for (let i = 0;i < binary.length; i++) {
|
|
215
|
-
bytes[i] = binary.charCodeAt(i);
|
|
216
|
-
}
|
|
217
|
-
return bytes;
|
|
218
|
-
}
|
|
219
|
-
return new Uint8Array(Buffer.from(value, "base64"));
|
|
220
|
-
}
|
|
221
|
-
validate(value) {
|
|
222
|
-
return value instanceof Uint8Array;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
class JsonType extends FieldType {
|
|
227
|
-
_type = "json";
|
|
228
|
-
_tsType;
|
|
229
|
-
serialize(value) {
|
|
230
|
-
return value;
|
|
231
|
-
}
|
|
232
|
-
deserialize(value) {
|
|
233
|
-
return value;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
class EnumType extends FieldType {
|
|
238
|
-
values;
|
|
239
|
-
_type = "enum";
|
|
240
|
-
_tsType;
|
|
241
|
-
constructor(values) {
|
|
242
|
-
super();
|
|
243
|
-
this.values = values;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
class ObjectType extends FieldType {
|
|
248
|
-
_type = "object";
|
|
249
|
-
_tsType;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
class ArrayType extends FieldType {
|
|
253
|
-
itemType;
|
|
254
|
-
_type = "array";
|
|
255
|
-
_tsType;
|
|
256
|
-
constructor(itemType) {
|
|
257
|
-
super();
|
|
258
|
-
this.itemType = itemType;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
class ScalarType extends FieldType {
|
|
263
|
-
definition;
|
|
264
|
-
_type = "scalar";
|
|
265
|
-
_tsType;
|
|
266
|
-
constructor(definition) {
|
|
267
|
-
super();
|
|
268
|
-
this.definition = definition;
|
|
269
|
-
}
|
|
270
|
-
serialize(value) {
|
|
271
|
-
if (this.definition.validate && !this.definition.validate(value)) {
|
|
272
|
-
throw new Error(`Validation failed for scalar type: ${this.definition.name}`);
|
|
273
|
-
}
|
|
274
|
-
return this.definition.serialize(value);
|
|
275
|
-
}
|
|
276
|
-
deserialize(value) {
|
|
277
|
-
return this.definition.deserialize(value);
|
|
278
|
-
}
|
|
279
|
-
validate(value) {
|
|
280
|
-
return this.definition.validate ? this.definition.validate(value) : true;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
var CustomType = ScalarType;
|
|
284
|
-
|
|
285
|
-
class HasOneType extends FieldType {
|
|
286
|
-
target;
|
|
287
|
-
foreignKey;
|
|
288
|
-
_type = "hasOne";
|
|
289
|
-
_tsType;
|
|
290
|
-
_relationKind = "hasOne";
|
|
291
|
-
constructor(target, foreignKey) {
|
|
292
|
-
super();
|
|
293
|
-
this.target = target;
|
|
294
|
-
this.foreignKey = foreignKey;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
class HasManyType extends FieldType {
|
|
299
|
-
target;
|
|
300
|
-
foreignKey;
|
|
301
|
-
_type = "hasMany";
|
|
302
|
-
_tsType;
|
|
303
|
-
_relationKind = "hasMany";
|
|
304
|
-
constructor(target, foreignKey) {
|
|
305
|
-
super();
|
|
306
|
-
this.target = target;
|
|
307
|
-
this.foreignKey = foreignKey;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
class BelongsToType extends FieldType {
|
|
312
|
-
target;
|
|
313
|
-
foreignKey;
|
|
314
|
-
_type = "belongsTo";
|
|
315
|
-
_tsType;
|
|
316
|
-
_relationKind = "belongsTo";
|
|
317
|
-
constructor(target, foreignKey) {
|
|
318
|
-
super();
|
|
319
|
-
this.target = target;
|
|
320
|
-
this.foreignKey = foreignKey;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
class LazyOneType extends FieldType {
|
|
325
|
-
targetRef;
|
|
326
|
-
_type = "lazyOne";
|
|
327
|
-
_tsType;
|
|
328
|
-
_relationKind = "one";
|
|
329
|
-
constructor(targetRef) {
|
|
330
|
-
super();
|
|
331
|
-
this.targetRef = targetRef;
|
|
332
|
-
}
|
|
333
|
-
getTarget() {
|
|
334
|
-
return this.targetRef();
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
class LazyManyType extends FieldType {
|
|
339
|
-
targetRef;
|
|
340
|
-
_type = "lazyMany";
|
|
341
|
-
_tsType;
|
|
342
|
-
_relationKind = "many";
|
|
343
|
-
constructor(targetRef) {
|
|
344
|
-
super();
|
|
345
|
-
this.targetRef = targetRef;
|
|
346
|
-
}
|
|
347
|
-
getTarget() {
|
|
348
|
-
return this.targetRef();
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
var t = {
|
|
352
|
-
id: () => new IdType,
|
|
353
|
-
string: () => new StringType,
|
|
354
|
-
int: () => new IntType,
|
|
355
|
-
float: () => new FloatType,
|
|
356
|
-
boolean: () => new BooleanType,
|
|
357
|
-
datetime: () => new DateTimeType,
|
|
358
|
-
timestamp: () => new TimestampType,
|
|
359
|
-
date: () => new DateType,
|
|
360
|
-
decimal: () => new DecimalType,
|
|
361
|
-
bigint: () => new BigIntType,
|
|
362
|
-
bytes: () => new BytesType,
|
|
363
|
-
json: () => new JsonType,
|
|
364
|
-
enum: (values) => new EnumType(values),
|
|
365
|
-
object: () => new ObjectType,
|
|
366
|
-
array: (itemType) => new ArrayType(itemType),
|
|
367
|
-
custom: (definition) => new CustomType(definition),
|
|
368
|
-
hasOne: (target) => new HasOneType(target),
|
|
369
|
-
hasMany: (target) => new HasManyType(target),
|
|
370
|
-
belongsTo: (target) => new BelongsToType(target),
|
|
371
|
-
one: (targetRef) => new LazyOneType(targetRef),
|
|
372
|
-
many: (targetRef) => new LazyManyType(targetRef)
|
|
373
|
-
};
|
|
374
|
-
function createContextualField(field) {
|
|
375
|
-
const wrapper = {
|
|
376
|
-
field,
|
|
377
|
-
resolve(fn) {
|
|
378
|
-
return field.resolve(fn);
|
|
379
|
-
},
|
|
380
|
-
subscribe(fn) {
|
|
381
|
-
return field.subscribe(fn);
|
|
382
|
-
},
|
|
383
|
-
nullable() {
|
|
384
|
-
return createContextualField(field.nullable());
|
|
385
|
-
},
|
|
386
|
-
optional() {
|
|
387
|
-
return createContextualField(field.optional());
|
|
388
|
-
},
|
|
389
|
-
default(value) {
|
|
390
|
-
return createContextualField(field.default(value));
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
return Object.assign(Object.create(field), wrapper);
|
|
394
|
-
}
|
|
395
|
-
function createTypeBuilder() {
|
|
396
|
-
return {
|
|
397
|
-
id: () => createContextualField(new IdType),
|
|
398
|
-
string: () => createContextualField(new StringType),
|
|
399
|
-
int: () => createContextualField(new IntType),
|
|
400
|
-
float: () => createContextualField(new FloatType),
|
|
401
|
-
boolean: () => createContextualField(new BooleanType),
|
|
402
|
-
datetime: () => createContextualField(new DateTimeType),
|
|
403
|
-
timestamp: () => createContextualField(new TimestampType),
|
|
404
|
-
date: () => createContextualField(new DateType),
|
|
405
|
-
decimal: () => createContextualField(new DecimalType),
|
|
406
|
-
bigint: () => createContextualField(new BigIntType),
|
|
407
|
-
bytes: () => createContextualField(new BytesType),
|
|
408
|
-
json: () => createContextualField(new ObjectType),
|
|
409
|
-
enum: (values) => createContextualField(new EnumType(values)),
|
|
410
|
-
object: () => createContextualField(new ObjectType),
|
|
411
|
-
array: (itemType) => createContextualField(new ArrayType(itemType)),
|
|
412
|
-
custom: (definition) => createContextualField(new CustomType(definition)),
|
|
413
|
-
hasOne: (target) => createContextualField(new HasOneType(target)),
|
|
414
|
-
hasMany: (target) => createContextualField(new HasManyType(target)),
|
|
415
|
-
belongsTo: (target) => createContextualField(new BelongsToType(target)),
|
|
416
|
-
one: (targetRef) => createContextualField(new LazyOneType(targetRef)),
|
|
417
|
-
many: (targetRef) => createContextualField(new LazyManyType(targetRef))
|
|
418
|
-
};
|
|
419
|
-
}
|
|
6
|
+
var MODEL_SYMBOL = Symbol("lens:model");
|
|
420
7
|
var LIST_SYMBOL = Symbol("lens:list");
|
|
421
8
|
var NULLABLE_SYMBOL = Symbol("lens:nullable");
|
|
422
|
-
var MODEL_SYMBOL = Symbol("lens:model");
|
|
423
|
-
var ENTITY_SYMBOL = Symbol("lens:entity");
|
|
424
|
-
function defineEntity(nameOrFields, maybeFieldsOrBuilder) {
|
|
425
|
-
if (typeof nameOrFields === "object" && maybeFieldsOrBuilder === undefined) {
|
|
426
|
-
const fields2 = nameOrFields;
|
|
427
|
-
return createEntityDef(undefined, fields2);
|
|
428
|
-
}
|
|
429
|
-
const name = nameOrFields;
|
|
430
|
-
if (maybeFieldsOrBuilder === undefined) {
|
|
431
|
-
return new EntityBuilder_(name);
|
|
432
|
-
}
|
|
433
|
-
if (typeof maybeFieldsOrBuilder === "function") {
|
|
434
|
-
const builder = maybeFieldsOrBuilder;
|
|
435
|
-
const fields2 = builder(t);
|
|
436
|
-
return createEntityDef(name, fields2);
|
|
437
|
-
}
|
|
438
|
-
const fields = maybeFieldsOrBuilder;
|
|
439
|
-
return createEntityDef(name, fields);
|
|
440
|
-
}
|
|
441
|
-
function createEntityDef(name, fields) {
|
|
442
|
-
return {
|
|
443
|
-
[ENTITY_SYMBOL]: true,
|
|
444
|
-
_name: name,
|
|
445
|
-
fields,
|
|
446
|
-
"~entity": {
|
|
447
|
-
name,
|
|
448
|
-
type: undefined
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
var entity2 = Object.assign(defineEntity, (name) => new EntityBuilder_(name));
|
|
453
|
-
|
|
454
|
-
class EntityBuilder_ {
|
|
455
|
-
_name;
|
|
456
|
-
constructor(_name) {
|
|
457
|
-
this._name = _name;
|
|
458
|
-
}
|
|
459
|
-
define(builder) {
|
|
460
|
-
const contextualBuilder = createTypeBuilder();
|
|
461
|
-
const fields = builder(contextualBuilder);
|
|
462
|
-
return createEntityDef(this._name, fields);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
9
|
var valueStrategy = {
|
|
466
10
|
name: "value",
|
|
467
11
|
encode(_prev, next) {
|
|
@@ -1099,8 +643,8 @@ class SubscriptionRegistry {
|
|
|
1099
643
|
}
|
|
1100
644
|
}
|
|
1101
645
|
}
|
|
1102
|
-
getByEntity(
|
|
1103
|
-
const entityKey = `${
|
|
646
|
+
getByEntity(entity2, entityId) {
|
|
647
|
+
const entityKey = `${entity2}:${entityId}`;
|
|
1104
648
|
const ids = this.entityIndex.get(entityKey);
|
|
1105
649
|
if (!ids)
|
|
1106
650
|
return [];
|
|
@@ -1317,10 +861,17 @@ function applyOp(state, op2) {
|
|
|
1317
861
|
return state;
|
|
1318
862
|
}
|
|
1319
863
|
}
|
|
864
|
+
var FORBIDDEN_PATH_SEGMENTS = new Set(["__proto__", "constructor", "prototype"]);
|
|
1320
865
|
function parsePath(path) {
|
|
1321
866
|
if (!path)
|
|
1322
867
|
return [];
|
|
1323
|
-
|
|
868
|
+
const segments = path.split(".");
|
|
869
|
+
for (const segment of segments) {
|
|
870
|
+
if (FORBIDDEN_PATH_SEGMENTS.has(segment)) {
|
|
871
|
+
throw new Error(`Forbidden path segment: "${segment}" - potential prototype pollution attack`);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
return segments;
|
|
1324
875
|
}
|
|
1325
876
|
function getAtPath(state, path) {
|
|
1326
877
|
const segments = parsePath(path);
|
|
@@ -1385,6 +936,12 @@ function updateAtPath(state, segments, transform) {
|
|
|
1385
936
|
if (Array.isArray(state)) {
|
|
1386
937
|
const result = [...state];
|
|
1387
938
|
const idx = parseInt(head, 10);
|
|
939
|
+
if (Number.isNaN(idx) || idx < 0) {
|
|
940
|
+
return {
|
|
941
|
+
...Object.fromEntries(state.map((v, i) => [String(i), v])),
|
|
942
|
+
[head]: updateAtPath(undefined, tail, transform)
|
|
943
|
+
};
|
|
944
|
+
}
|
|
1388
945
|
result[idx] = updateAtPath(result[idx], tail, transform);
|
|
1389
946
|
return result;
|
|
1390
947
|
}
|
|
@@ -1787,6 +1344,15 @@ function filterToSelection(data, selection) {
|
|
|
1787
1344
|
}
|
|
1788
1345
|
return result;
|
|
1789
1346
|
}
|
|
1347
|
+
function isQueryCapable(t) {
|
|
1348
|
+
return "query" in t && typeof t.query === "function";
|
|
1349
|
+
}
|
|
1350
|
+
function isMutationCapable(t) {
|
|
1351
|
+
return "mutation" in t && typeof t.mutation === "function";
|
|
1352
|
+
}
|
|
1353
|
+
function isSubscriptionCapable(t) {
|
|
1354
|
+
return "subscription" in t && typeof t.subscription === "function";
|
|
1355
|
+
}
|
|
1790
1356
|
function hasAnySubscription(entities, entityName, select, visited = new Set) {
|
|
1791
1357
|
if (!entities)
|
|
1792
1358
|
return false;
|
|
@@ -1859,7 +1425,16 @@ class ClientImpl {
|
|
|
1859
1425
|
processedOp = await plugin.beforeRequest(processedOp);
|
|
1860
1426
|
}
|
|
1861
1427
|
}
|
|
1862
|
-
|
|
1428
|
+
let resultOrObservable;
|
|
1429
|
+
if (processedOp.type === "mutation" && isMutationCapable(this.transport)) {
|
|
1430
|
+
resultOrObservable = this.transport.mutation(processedOp);
|
|
1431
|
+
} else if (processedOp.type === "subscription" && isSubscriptionCapable(this.transport)) {
|
|
1432
|
+
resultOrObservable = this.transport.subscription(processedOp);
|
|
1433
|
+
} else if (isQueryCapable(this.transport)) {
|
|
1434
|
+
resultOrObservable = this.transport.query(processedOp);
|
|
1435
|
+
} else {
|
|
1436
|
+
throw new Error(`Transport does not support ${processedOp.type} operations`);
|
|
1437
|
+
}
|
|
1863
1438
|
let result;
|
|
1864
1439
|
if (this.isObservable(resultOrObservable)) {
|
|
1865
1440
|
result = await this.firstValueFrom(resultOrObservable);
|
|
@@ -1937,6 +1512,8 @@ class ClientImpl {
|
|
|
1937
1512
|
return false;
|
|
1938
1513
|
if (meta.type === "subscription")
|
|
1939
1514
|
return true;
|
|
1515
|
+
if (meta.live)
|
|
1516
|
+
return true;
|
|
1940
1517
|
if (meta.type === "query" && meta.returnType && this.metadata?.entities) {
|
|
1941
1518
|
return hasAnySubscription(this.metadata.entities, meta.returnType, select);
|
|
1942
1519
|
}
|
|
@@ -2241,13 +1818,17 @@ class ClientImpl {
|
|
|
2241
1818
|
input,
|
|
2242
1819
|
meta: endpoint.mergedSelection ? { select: endpoint.mergedSelection } : {}
|
|
2243
1820
|
};
|
|
2244
|
-
const resultOrObservable = this.transport.
|
|
1821
|
+
const resultOrObservable = isSubscriptionCapable(this.transport) ? this.transport.subscription(op2) : isQueryCapable(this.transport) ? this.transport.query(op2) : Promise.reject(new Error("Transport does not support subscriptions"));
|
|
2245
1822
|
if (this.isObservable(resultOrObservable)) {
|
|
2246
1823
|
const subscription = resultOrObservable.subscribe({
|
|
2247
1824
|
next: (message) => {
|
|
2248
1825
|
if (isSnapshot(message)) {
|
|
2249
1826
|
this.distributeData(endpoint, message.data);
|
|
2250
1827
|
} else if (isOps(message)) {
|
|
1828
|
+
if (endpoint.data === null || endpoint.data === undefined) {
|
|
1829
|
+
console.warn(`[Lens] Received ops message before snapshot for ${path}. Skipping update.`);
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
2251
1832
|
try {
|
|
2252
1833
|
const newData = applyOps(endpoint.data, message.ops);
|
|
2253
1834
|
this.distributeData(endpoint, newData);
|
|
@@ -2301,13 +1882,19 @@ class ClientImpl {
|
|
|
2301
1882
|
if (isSnapshot(response)) {
|
|
2302
1883
|
return { data: response.data };
|
|
2303
1884
|
}
|
|
2304
|
-
|
|
1885
|
+
throw new Error(`Mutation received unexpected message type: ${response.$}. Mutations should return snapshot.`);
|
|
2305
1886
|
}
|
|
2306
1887
|
createAccessor(path) {
|
|
2307
1888
|
return (descriptor) => {
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
1889
|
+
let input;
|
|
1890
|
+
let select;
|
|
1891
|
+
if (descriptor && typeof descriptor === "object" && (("input" in descriptor) || ("select" in descriptor))) {
|
|
1892
|
+
input = descriptor.input;
|
|
1893
|
+
select = descriptor.select;
|
|
1894
|
+
} else {
|
|
1895
|
+
input = descriptor;
|
|
1896
|
+
select = undefined;
|
|
1897
|
+
}
|
|
2311
1898
|
const queryResult = this.executeQuery(path, input, select);
|
|
2312
1899
|
const originalThen = queryResult.then.bind(queryResult);
|
|
2313
1900
|
queryResult.then = async (onfulfilled, onrejected) => {
|
|
@@ -2384,15 +1971,17 @@ var http = function http2(options) {
|
|
|
2384
1971
|
}
|
|
2385
1972
|
return response.json();
|
|
2386
1973
|
},
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
}
|
|
1974
|
+
query(op2) {
|
|
1975
|
+
return executeRequest(baseUrl, op2, {
|
|
1976
|
+
headers: {
|
|
1977
|
+
...defaultHeaders,
|
|
1978
|
+
...op2.meta?.headers ?? {}
|
|
1979
|
+
},
|
|
1980
|
+
fetch: fetchImpl,
|
|
1981
|
+
timeout: op2.meta?.timeout
|
|
1982
|
+
});
|
|
1983
|
+
},
|
|
1984
|
+
mutation(op2) {
|
|
2396
1985
|
return executeRequest(baseUrl, op2, {
|
|
2397
1986
|
headers: {
|
|
2398
1987
|
...defaultHeaders,
|
|
@@ -2401,6 +1990,14 @@ var http = function http2(options) {
|
|
|
2401
1990
|
fetch: fetchImpl,
|
|
2402
1991
|
timeout: op2.meta?.timeout
|
|
2403
1992
|
});
|
|
1993
|
+
},
|
|
1994
|
+
subscription(op2) {
|
|
1995
|
+
return createPollingObservable(baseUrl, op2, {
|
|
1996
|
+
interval: pollInterval,
|
|
1997
|
+
maxRetries,
|
|
1998
|
+
headers: defaultHeaders,
|
|
1999
|
+
fetch: fetchImpl
|
|
2000
|
+
});
|
|
2404
2001
|
}
|
|
2405
2002
|
};
|
|
2406
2003
|
};
|
|
@@ -2499,6 +2096,18 @@ function createPollingObservable(baseUrl, op2, options) {
|
|
|
2499
2096
|
}
|
|
2500
2097
|
};
|
|
2501
2098
|
}
|
|
2099
|
+
function firstValueFromServer(observable) {
|
|
2100
|
+
return new Promise((resolve, reject) => {
|
|
2101
|
+
let subscription;
|
|
2102
|
+
subscription = observable.subscribe({
|
|
2103
|
+
next: (value) => {
|
|
2104
|
+
subscription?.unsubscribe?.();
|
|
2105
|
+
resolve(value);
|
|
2106
|
+
},
|
|
2107
|
+
error: reject
|
|
2108
|
+
});
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2502
2111
|
http.server = function httpServer(options) {
|
|
2503
2112
|
const { port, path = "", hostname = "0.0.0.0" } = options;
|
|
2504
2113
|
return {
|
|
@@ -2515,7 +2124,7 @@ http.server = function httpServer(options) {
|
|
|
2515
2124
|
if (url.pathname === basePath && req.method === "POST") {
|
|
2516
2125
|
try {
|
|
2517
2126
|
const body = await req.json();
|
|
2518
|
-
const result = await server.execute(body);
|
|
2127
|
+
const result = await firstValueFromServer(server.execute(body));
|
|
2519
2128
|
return Response.json(result);
|
|
2520
2129
|
} catch (error) {
|
|
2521
2130
|
return Response.json({ error: { message: error.message } }, { status: 500 });
|
|
@@ -2695,8 +2304,8 @@ class SubscriptionRegistry2 {
|
|
|
2695
2304
|
}
|
|
2696
2305
|
}
|
|
2697
2306
|
}
|
|
2698
|
-
getByEntity(
|
|
2699
|
-
const entityKey = `${
|
|
2307
|
+
getByEntity(entity2, entityId) {
|
|
2308
|
+
const entityKey = `${entity2}:${entityId}`;
|
|
2700
2309
|
const ids = this.entityIndex.get(entityKey);
|
|
2701
2310
|
if (!ids)
|
|
2702
2311
|
return [];
|
|
@@ -3025,21 +2634,6 @@ function createClient2(config) {
|
|
|
3025
2634
|
}
|
|
3026
2635
|
return createProxy("");
|
|
3027
2636
|
}
|
|
3028
|
-
// src/context.tsx
|
|
3029
|
-
import { createContext, useContext } from "solid-js";
|
|
3030
|
-
var LensClientContext = createContext();
|
|
3031
|
-
var LensProvider = (props) => {
|
|
3032
|
-
return /* @__PURE__ */ React.createElement(LensClientContext.Provider, {
|
|
3033
|
-
value: props.client
|
|
3034
|
-
}, props.children);
|
|
3035
|
-
};
|
|
3036
|
-
function useLensClient() {
|
|
3037
|
-
const client = useContext(LensClientContext);
|
|
3038
|
-
if (!client) {
|
|
3039
|
-
throw new Error("useLensClient must be used within a <LensProvider>. " + "Make sure to wrap your app with <LensProvider client={client}>.");
|
|
3040
|
-
}
|
|
3041
|
-
return client;
|
|
3042
|
-
}
|
|
3043
2637
|
// src/primitives.ts
|
|
3044
2638
|
import { createEffect as createEffect2, createSignal as createSignal2, onCleanup as onCleanup2 } from "solid-js";
|
|
3045
2639
|
function resolveQuery(input) {
|
|
@@ -3194,10 +2788,8 @@ function createLazyQuery(queryInput) {
|
|
|
3194
2788
|
};
|
|
3195
2789
|
}
|
|
3196
2790
|
export {
|
|
3197
|
-
useLensClient,
|
|
3198
2791
|
createQuery,
|
|
3199
2792
|
createMutation,
|
|
3200
2793
|
createLazyQuery,
|
|
3201
|
-
createClient2 as createClient
|
|
3202
|
-
LensProvider
|
|
2794
|
+
createClient2 as createClient
|
|
3203
2795
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sylphx/lens-solid",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.14",
|
|
4
4
|
"description": "SolidJS bindings for Lens API framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"author": "SylphxAI",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@sylphx/lens-client": "^
|
|
35
|
-
"@sylphx/lens-core": "^
|
|
34
|
+
"@sylphx/lens-client": "^3.0.0",
|
|
35
|
+
"@sylphx/lens-core": "^4.0.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"solid-js": ">=1.8.0"
|
package/src/index.ts
CHANGED
|
@@ -25,10 +25,6 @@
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
// =============================================================================
|
|
29
|
-
// New API (v4) - Recommended
|
|
30
|
-
// =============================================================================
|
|
31
|
-
|
|
32
28
|
export {
|
|
33
29
|
createClient,
|
|
34
30
|
type MutationEndpoint,
|
|
@@ -40,27 +36,14 @@ export {
|
|
|
40
36
|
type TypedClient,
|
|
41
37
|
} from "./create.js";
|
|
42
38
|
|
|
43
|
-
// =============================================================================
|
|
44
|
-
// Legacy API (v3) - Deprecated
|
|
45
|
-
// =============================================================================
|
|
46
|
-
|
|
47
|
-
export { LensProvider, type LensProviderProps, useLensClient } from "./context.js";
|
|
48
|
-
|
|
49
|
-
// =============================================================================
|
|
50
|
-
// Reactive Primitives
|
|
51
|
-
// =============================================================================
|
|
52
|
-
|
|
53
39
|
export {
|
|
54
40
|
type CreateLazyQueryResult,
|
|
55
41
|
type CreateMutationResult,
|
|
56
42
|
type CreateQueryOptions,
|
|
57
43
|
type CreateQueryResult,
|
|
58
44
|
createLazyQuery,
|
|
59
|
-
// Mutation primitive
|
|
60
45
|
createMutation,
|
|
61
|
-
// Query primitives
|
|
62
46
|
createQuery,
|
|
63
47
|
type MutationFn,
|
|
64
|
-
// Types
|
|
65
48
|
type QueryInput,
|
|
66
49
|
} from "./primitives.js";
|