tinybase 9.5.0-beta.0 → 9.5.0-beta.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.
- package/@types/_internal/store/with-schemas/index.d.ts +43 -8
- package/@types/mergeable-store/with-schemas/index.d.ts +30 -11
- package/@types/queries/index.d.ts +11 -11
- package/@types/queries/with-schemas/index.d.ts +17 -3
- package/@types/schematizers/index.d.ts +6 -4
- package/@types/schematizers/schematizer-arktype/index.d.ts +6 -6
- package/@types/schematizers/schematizer-arktype/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/schematizer-effect/index.d.ts +9 -11
- package/@types/schematizers/schematizer-effect/with-schemas/index.d.ts +114 -1
- package/@types/schematizers/schematizer-typebox/index.d.ts +7 -7
- package/@types/schematizers/schematizer-typebox/with-schemas/index.d.ts +114 -1
- package/@types/schematizers/schematizer-valibot/index.d.ts +6 -6
- package/@types/schematizers/schematizer-valibot/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/schematizer-yup/index.d.ts +5 -4
- package/@types/schematizers/schematizer-yup/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/schematizer-zod/index.d.ts +6 -6
- package/@types/schematizers/schematizer-zod/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/with-schemas/index.d.ts +113 -4
- package/@types/store/index.d.ts +175 -16
- package/@types/store/with-schemas/index.d.ts +238 -55
- package/@types/synchronizers/with-schemas/index.d.ts +12 -2
- package/@types/ui-react/with-schemas/index.d.ts +576 -7
- package/@types/ui-react-dom/with-schemas/index.d.ts +84 -0
- package/@types/ui-solid/with-schemas/index.d.ts +340 -7
- package/@types/ui-solid-dom/with-schemas/index.d.ts +84 -0
- package/@types/ui-svelte/with-schemas/index.d.ts +30 -0
- package/@types/ui-svelte-dom/with-schemas/index.d.ts +84 -0
- package/agents.md +4 -0
- package/index.js +76 -22
- package/mergeable-store/index.js +76 -22
- package/mergeable-store/with-schemas/index.js +76 -22
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/mergeable-store/index.js +1 -1
- package/min/mergeable-store/index.js.gz +0 -0
- package/min/mergeable-store/with-schemas/index.js +1 -1
- package/min/mergeable-store/with-schemas/index.js.gz +0 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/schematizers/index.js +1 -1
- package/min/schematizers/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/index.js +1 -1
- package/min/schematizers/schematizer-arktype/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-arktype/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/index.js +1 -1
- package/min/schematizers/schematizer-effect/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-effect/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/index.js +1 -1
- package/min/schematizers/schematizer-typebox/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-typebox/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-valibot/index.js +1 -1
- package/min/schematizers/schematizer-valibot/index.js.gz +0 -0
- package/min/schematizers/schematizer-valibot/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-valibot/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-yup/index.js +1 -1
- package/min/schematizers/schematizer-yup/index.js.gz +0 -0
- package/min/schematizers/schematizer-yup/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-yup/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/index.js +1 -1
- package/min/schematizers/schematizer-zod/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-zod/with-schemas/index.js.gz +0 -0
- package/min/schematizers/with-schemas/index.js +1 -1
- package/min/schematizers/with-schemas/index.js.gz +0 -0
- package/min/store/index.js +1 -1
- package/min/store/index.js.gz +0 -0
- package/min/store/with-schemas/index.js +1 -1
- package/min/store/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/min/ui-solid-inspector/index.js +1 -1
- package/min/ui-solid-inspector/index.js.gz +0 -0
- package/min/ui-solid-inspector/with-schemas/index.js +1 -1
- package/min/ui-solid-inspector/with-schemas/index.js.gz +0 -0
- package/min/ui-svelte-inspector/index.js +1 -1
- package/min/ui-svelte-inspector/index.js.gz +0 -0
- package/min/ui-svelte-inspector/with-schemas/index.js +1 -1
- package/min/ui-svelte-inspector/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +76 -22
- package/omni/with-schemas/index.js +76 -22
- package/package.json +2 -2
- package/readme.md +14 -14
- package/releases.md +95 -65
- package/schematizers/index.js +54 -6
- package/schematizers/schematizer-arktype/index.js +99 -19
- package/schematizers/schematizer-arktype/with-schemas/index.js +99 -19
- package/schematizers/schematizer-effect/index.js +101 -11
- package/schematizers/schematizer-effect/with-schemas/index.js +101 -11
- package/schematizers/schematizer-typebox/index.js +87 -11
- package/schematizers/schematizer-typebox/with-schemas/index.js +87 -11
- package/schematizers/schematizer-valibot/index.js +125 -21
- package/schematizers/schematizer-valibot/with-schemas/index.js +125 -21
- package/schematizers/schematizer-yup/index.js +58 -14
- package/schematizers/schematizer-yup/with-schemas/index.js +58 -14
- package/schematizers/schematizer-zod/index.js +131 -12
- package/schematizers/schematizer-zod/with-schemas/index.js +131 -12
- package/schematizers/with-schemas/index.js +54 -6
- package/store/index.js +76 -22
- package/store/with-schemas/index.js +76 -22
- package/ui-react-inspector/index.js +76 -22
- package/ui-react-inspector/with-schemas/index.js +76 -22
- package/ui-solid-inspector/index.js +76 -22
- package/ui-solid-inspector/with-schemas/index.js +76 -22
- package/ui-svelte-inspector/index.js +76 -22
- package/ui-svelte-inspector/with-schemas/index.js +76 -22
- package/with-schemas/index.js +76 -22
|
@@ -230,6 +230,18 @@ export type TableInHtmlTableProps<
|
|
|
230
230
|
[CellId in CellIdFromSchema<Schemas[0], TableId>]?:
|
|
231
231
|
string | CustomCell<Schemas, TableId, CellId>;
|
|
232
232
|
};
|
|
233
|
+
/**
|
|
234
|
+
* An optional list of extra Cells to render before the main table Cells.
|
|
235
|
+
* @category Prop
|
|
236
|
+
* @since v6.6.0
|
|
237
|
+
*/
|
|
238
|
+
readonly extraCellsBefore?: ExtraRowCell<Schemas, TableId>[];
|
|
239
|
+
/**
|
|
240
|
+
* An optional list of extra Cells to render after the main table Cells.
|
|
241
|
+
* @category Prop
|
|
242
|
+
* @since v6.6.0
|
|
243
|
+
*/
|
|
244
|
+
readonly extraCellsAfter?: ExtraRowCell<Schemas, TableId>[];
|
|
233
245
|
}
|
|
234
246
|
: never
|
|
235
247
|
: never;
|
|
@@ -310,6 +322,18 @@ export type SortedTableInHtmlTableProps<
|
|
|
310
322
|
string | CustomCell<Schemas, TableId, CellId>;
|
|
311
323
|
};
|
|
312
324
|
/**
|
|
325
|
+
* An optional list of extra Cells to render before the main table Cells.
|
|
326
|
+
* @category Prop
|
|
327
|
+
* @since v6.6.0
|
|
328
|
+
*/
|
|
329
|
+
readonly extraCellsBefore?: ExtraRowCell<Schemas, TableId>[];
|
|
330
|
+
/**
|
|
331
|
+
* An optional list of extra Cells to render after the main table Cells.
|
|
332
|
+
* @category Prop
|
|
333
|
+
* @since v6.6.0
|
|
334
|
+
*/
|
|
335
|
+
readonly extraCellsAfter?: ExtraRowCell<Schemas, TableId>[];
|
|
336
|
+
/**
|
|
313
337
|
* Whether the table should be interactive such that clicking a header changes
|
|
314
338
|
* the sorting and/or direction.
|
|
315
339
|
* @category Prop
|
|
@@ -377,6 +401,18 @@ export type ValuesInHtmlTableProps<Schemas extends OptionalSchemas> = {
|
|
|
377
401
|
* @since v4.1.0
|
|
378
402
|
*/
|
|
379
403
|
readonly getValueComponentProps?: (valueId: Id) => {[prop: string]: any};
|
|
404
|
+
/**
|
|
405
|
+
* An optional list of extra Cells to render before the main table Cells.
|
|
406
|
+
* @category Prop
|
|
407
|
+
* @since v6.6.0
|
|
408
|
+
*/
|
|
409
|
+
readonly extraCellsBefore?: ExtraValueCell<Schemas>[];
|
|
410
|
+
/**
|
|
411
|
+
* An optional list of extra Cells to render after the main table Cells.
|
|
412
|
+
* @category Prop
|
|
413
|
+
* @since v6.6.0
|
|
414
|
+
*/
|
|
415
|
+
readonly extraCellsAfter?: ExtraValueCell<Schemas>[];
|
|
380
416
|
};
|
|
381
417
|
|
|
382
418
|
/**
|
|
@@ -425,6 +461,18 @@ export type SliceInHtmlTableProps<Schemas extends OptionalSchemas> = {
|
|
|
425
461
|
*/
|
|
426
462
|
readonly customCells?:
|
|
427
463
|
Ids | {[cellId: Id]: string | CustomCell<NoSchemas, Id, Id>};
|
|
464
|
+
/**
|
|
465
|
+
* An optional list of extra Cells to render before the main table Cells.
|
|
466
|
+
* @category Prop
|
|
467
|
+
* @since v6.6.0
|
|
468
|
+
*/
|
|
469
|
+
readonly extraCellsBefore?: ExtraRowCell<NoSchemas, Id>[];
|
|
470
|
+
/**
|
|
471
|
+
* An optional list of extra Cells to render after the main table Cells.
|
|
472
|
+
* @category Prop
|
|
473
|
+
* @since v6.6.0
|
|
474
|
+
*/
|
|
475
|
+
readonly extraCellsAfter?: ExtraRowCell<NoSchemas, Id>[];
|
|
428
476
|
};
|
|
429
477
|
|
|
430
478
|
/**
|
|
@@ -475,6 +523,18 @@ export type RelationshipInHtmlTableProps<Schemas extends OptionalSchemas> = {
|
|
|
475
523
|
*/
|
|
476
524
|
readonly customCells?:
|
|
477
525
|
Ids | {[cellId: Id]: string | CustomCell<NoSchemas, Id, Id>};
|
|
526
|
+
/**
|
|
527
|
+
* An optional list of extra Cells to render before the main table Cells.
|
|
528
|
+
* @category Prop
|
|
529
|
+
* @since v6.6.0
|
|
530
|
+
*/
|
|
531
|
+
readonly extraCellsBefore?: ExtraRowCell<NoSchemas, Id>[];
|
|
532
|
+
/**
|
|
533
|
+
* An optional list of extra Cells to render after the main table Cells.
|
|
534
|
+
* @category Prop
|
|
535
|
+
* @since v6.6.0
|
|
536
|
+
*/
|
|
537
|
+
readonly extraCellsAfter?: ExtraRowCell<NoSchemas, Id>[];
|
|
478
538
|
};
|
|
479
539
|
|
|
480
540
|
/**
|
|
@@ -510,6 +570,18 @@ export type ResultTableInHtmlTableProps<Schemas extends OptionalSchemas> = {
|
|
|
510
570
|
*/
|
|
511
571
|
readonly customCells?:
|
|
512
572
|
Ids | {[cellId: Id]: string | CustomResultCell<Schemas>};
|
|
573
|
+
/**
|
|
574
|
+
* An optional list of extra Cells to render before the main table Cells.
|
|
575
|
+
* @category Prop
|
|
576
|
+
* @since v6.6.0
|
|
577
|
+
*/
|
|
578
|
+
readonly extraCellsBefore?: ExtraRowCell<NoSchemas, Id>[];
|
|
579
|
+
/**
|
|
580
|
+
* An optional list of extra Cells to render after the main table Cells.
|
|
581
|
+
* @category Prop
|
|
582
|
+
* @since v6.6.0
|
|
583
|
+
*/
|
|
584
|
+
readonly extraCellsAfter?: ExtraRowCell<NoSchemas, Id>[];
|
|
513
585
|
};
|
|
514
586
|
|
|
515
587
|
/**
|
|
@@ -573,6 +645,18 @@ export type ResultSortedTableInHtmlTableProps<Schemas extends OptionalSchemas> =
|
|
|
573
645
|
readonly customCells?:
|
|
574
646
|
Ids | {[cellId: Id]: string | CustomResultCell<Schemas>};
|
|
575
647
|
/**
|
|
648
|
+
* An optional list of extra Cells to render before the main table Cells.
|
|
649
|
+
* @category Prop
|
|
650
|
+
* @since v6.6.0
|
|
651
|
+
*/
|
|
652
|
+
readonly extraCellsBefore?: ExtraRowCell<NoSchemas, Id>[];
|
|
653
|
+
/**
|
|
654
|
+
* An optional list of extra Cells to render after the main table Cells.
|
|
655
|
+
* @category Prop
|
|
656
|
+
* @since v6.6.0
|
|
657
|
+
*/
|
|
658
|
+
readonly extraCellsAfter?: ExtraRowCell<NoSchemas, Id>[];
|
|
659
|
+
/**
|
|
576
660
|
* Whether the table should be interactive such that clicking a header changes
|
|
577
661
|
* the sorting and/or direction.
|
|
578
662
|
* @category Prop
|
package/agents.md
CHANGED
|
@@ -568,6 +568,10 @@ All code examples in a guide file are concatenated and executed as a test:
|
|
|
568
568
|
|
|
569
569
|
When adding a new feature:
|
|
570
570
|
|
|
571
|
+
- Never alias imports in release-note examples to avoid shared-scope name
|
|
572
|
+
collisions. Import each symbol unaliased once in the most recent applicable
|
|
573
|
+
example, and remove conflicting imports from later examples in the page.
|
|
574
|
+
|
|
571
575
|
1. **Update `/site/guides/20_releases.md`** (NOT `/releases.md`):
|
|
572
576
|
- Add new version section at the top
|
|
573
577
|
- Include working code example that will be tested
|
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const FUNCTION = getTypeOf(getTypeOf);
|
|
|
8
8
|
const OBJECT = 'object';
|
|
9
9
|
const ARRAY = 'array';
|
|
10
10
|
const TYPE = 'type';
|
|
11
|
+
const ENUM = 'enum';
|
|
11
12
|
const DEFAULT = 'default';
|
|
12
13
|
const ALLOW_NULL = 'allowNull';
|
|
13
14
|
const NULL = 'null';
|
|
@@ -226,6 +227,14 @@ const getCellOrValueType = (cellOrValue) => {
|
|
|
226
227
|
const isCellOrValueOrUndefined = (cellOrValue) =>
|
|
227
228
|
isUndefined(cellOrValue) || !isUndefined(getCellOrValueType(cellOrValue));
|
|
228
229
|
const isJsonType = (type) => type == OBJECT || type == ARRAY;
|
|
230
|
+
const isCellOrValueSchemaType = (type) =>
|
|
231
|
+
isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
|
|
232
|
+
const isCellOrValueSchemaTypes = (types) =>
|
|
233
|
+
isArray(types)
|
|
234
|
+
? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
|
|
235
|
+
: isCellOrValueSchemaType(types);
|
|
236
|
+
const cellOrValueSchemaTypeIncludes = (types, type) =>
|
|
237
|
+
isArray(types) ? arrayHas(types, type) : types == type;
|
|
229
238
|
const encodeIfJson = (value) =>
|
|
230
239
|
isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
|
|
231
240
|
const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
|
|
@@ -1512,13 +1521,29 @@ const createStore = () => {
|
|
|
1512
1521
|
const validateCellOrValueSchema = (schema) => {
|
|
1513
1522
|
if (
|
|
1514
1523
|
!objValidate(schema, (_child, id2) =>
|
|
1515
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
1524
|
+
arrayHas([TYPE, ENUM, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
1516
1525
|
)
|
|
1517
1526
|
) {
|
|
1518
1527
|
return false;
|
|
1519
1528
|
}
|
|
1520
1529
|
const type = schema[TYPE];
|
|
1521
|
-
|
|
1530
|
+
const enumValues = schema[ENUM];
|
|
1531
|
+
if (
|
|
1532
|
+
isUndefined(enumValues)
|
|
1533
|
+
? !isCellOrValueSchemaTypes(type)
|
|
1534
|
+
: !isUndefined(type) ||
|
|
1535
|
+
!isArray(enumValues) ||
|
|
1536
|
+
isUndefined(enumValues[0]) ||
|
|
1537
|
+
!arrayEvery(enumValues, (enumValue) => {
|
|
1538
|
+
const enumType = getCellOrValueType(enumValue);
|
|
1539
|
+
return (
|
|
1540
|
+
!isNull(enumValue) &&
|
|
1541
|
+
!isUndefined(enumType) &&
|
|
1542
|
+
!isJsonType(enumType) &&
|
|
1543
|
+
!isReservedString(enumValue)
|
|
1544
|
+
);
|
|
1545
|
+
})
|
|
1546
|
+
) {
|
|
1522
1547
|
return false;
|
|
1523
1548
|
}
|
|
1524
1549
|
const defaultValue = schema[DEFAULT];
|
|
@@ -1527,7 +1552,12 @@ const createStore = () => {
|
|
|
1527
1552
|
}
|
|
1528
1553
|
if (!isNull(defaultValue)) {
|
|
1529
1554
|
if (
|
|
1530
|
-
|
|
1555
|
+
(isUndefined(enumValues)
|
|
1556
|
+
? !cellOrValueSchemaTypeIncludes(
|
|
1557
|
+
type,
|
|
1558
|
+
getCellOrValueType(defaultValue),
|
|
1559
|
+
)
|
|
1560
|
+
: !arrayHas(enumValues, defaultValue)) ||
|
|
1531
1561
|
isReservedString(defaultValue)
|
|
1532
1562
|
) {
|
|
1533
1563
|
objDel(schema, DEFAULT);
|
|
@@ -1554,13 +1584,15 @@ const createStore = () => {
|
|
|
1554
1584
|
isObject(tables) ? objMap(tables, cloneTable) : tables;
|
|
1555
1585
|
const cloneValues = (values) =>
|
|
1556
1586
|
isObject(values) ? objMap(values, getArg) : values;
|
|
1557
|
-
const isValidEncodedJson = (cellOrValue,
|
|
1587
|
+
const isValidEncodedJson = (cellOrValue, types) =>
|
|
1558
1588
|
acceptingEncodedData == 1 &&
|
|
1559
1589
|
isEncodedJson(cellOrValue) &&
|
|
1560
1590
|
tryReturn(() => {
|
|
1561
1591
|
const encodedType = getCellOrValueType(decodeIfJson(cellOrValue));
|
|
1562
1592
|
return (
|
|
1563
|
-
isJsonType(encodedType) &&
|
|
1593
|
+
isJsonType(encodedType) &&
|
|
1594
|
+
(isUndefined(types) ||
|
|
1595
|
+
cellOrValueSchemaTypeIncludes(types, encodedType))
|
|
1564
1596
|
);
|
|
1565
1597
|
}, false) == true;
|
|
1566
1598
|
const validateContent = isArray;
|
|
@@ -1613,7 +1645,8 @@ const createStore = () => {
|
|
|
1613
1645
|
: isReservedString(cell, acceptingEncodedData)
|
|
1614
1646
|
? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
|
|
1615
1647
|
: isEncodedJson(cell)
|
|
1616
|
-
?
|
|
1648
|
+
? isUndefined(cellSchema[ENUM]) &&
|
|
1649
|
+
isValidEncodedJson(cell, cellSchema[TYPE])
|
|
1617
1650
|
? cell
|
|
1618
1651
|
: cellInvalid(
|
|
1619
1652
|
tableId,
|
|
@@ -1622,23 +1655,36 @@ const createStore = () => {
|
|
|
1622
1655
|
cell,
|
|
1623
1656
|
cellSchema[DEFAULT],
|
|
1624
1657
|
)
|
|
1625
|
-
:
|
|
1626
|
-
?
|
|
1627
|
-
|
|
1658
|
+
: isUndefined(cellSchema[ENUM])
|
|
1659
|
+
? cellOrValueSchemaTypeIncludes(
|
|
1660
|
+
cellSchema[TYPE],
|
|
1661
|
+
getCellOrValueType(cell),
|
|
1662
|
+
)
|
|
1663
|
+
? encodeValid(cell, () =>
|
|
1664
|
+
cellInvalid(
|
|
1665
|
+
tableId,
|
|
1666
|
+
rowId,
|
|
1667
|
+
cellId,
|
|
1668
|
+
cell,
|
|
1669
|
+
cellSchema[DEFAULT],
|
|
1670
|
+
),
|
|
1671
|
+
)
|
|
1672
|
+
: cellInvalid(
|
|
1673
|
+
tableId,
|
|
1674
|
+
rowId,
|
|
1675
|
+
cellId,
|
|
1676
|
+
cell,
|
|
1677
|
+
cellSchema[DEFAULT],
|
|
1678
|
+
)
|
|
1679
|
+
: arrayHas(cellSchema[ENUM], cell)
|
|
1680
|
+
? cell
|
|
1681
|
+
: cellInvalid(
|
|
1628
1682
|
tableId,
|
|
1629
1683
|
rowId,
|
|
1630
1684
|
cellId,
|
|
1631
1685
|
cell,
|
|
1632
1686
|
cellSchema[DEFAULT],
|
|
1633
1687
|
),
|
|
1634
|
-
)
|
|
1635
|
-
: cellInvalid(
|
|
1636
|
-
tableId,
|
|
1637
|
-
rowId,
|
|
1638
|
-
cellId,
|
|
1639
|
-
cell,
|
|
1640
|
-
cellSchema[DEFAULT],
|
|
1641
|
-
),
|
|
1642
1688
|
() => cellInvalid(tableId, rowId, cellId, cell),
|
|
1643
1689
|
)
|
|
1644
1690
|
: isUndefined(getCellOrValueType(cell)) ||
|
|
@@ -1683,14 +1729,22 @@ const createStore = () => {
|
|
|
1683
1729
|
: isReservedString(value, acceptingEncodedData)
|
|
1684
1730
|
? valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
1685
1731
|
: isEncodedJson(value)
|
|
1686
|
-
?
|
|
1732
|
+
? isUndefined(valueSchema[ENUM]) &&
|
|
1733
|
+
isValidEncodedJson(value, valueSchema[TYPE])
|
|
1687
1734
|
? value
|
|
1688
1735
|
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
1689
|
-
:
|
|
1690
|
-
?
|
|
1691
|
-
|
|
1736
|
+
: isUndefined(valueSchema[ENUM])
|
|
1737
|
+
? cellOrValueSchemaTypeIncludes(
|
|
1738
|
+
valueSchema[TYPE],
|
|
1739
|
+
getCellOrValueType(value),
|
|
1692
1740
|
)
|
|
1693
|
-
|
|
1741
|
+
? encodeValid(value, () =>
|
|
1742
|
+
valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
1743
|
+
)
|
|
1744
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
1745
|
+
: arrayHas(valueSchema[ENUM], value)
|
|
1746
|
+
? value
|
|
1747
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
1694
1748
|
() => valueInvalid(valueId, value),
|
|
1695
1749
|
)
|
|
1696
1750
|
: isUndefined(getCellOrValueType(value)) ||
|
package/mergeable-store/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const FUNCTION = getTypeOf(getTypeOf);
|
|
|
8
8
|
const OBJECT = 'object';
|
|
9
9
|
const ARRAY = 'array';
|
|
10
10
|
const TYPE = 'type';
|
|
11
|
+
const ENUM = 'enum';
|
|
11
12
|
const DEFAULT = 'default';
|
|
12
13
|
const ALLOW_NULL = 'allowNull';
|
|
13
14
|
const NULL = 'null';
|
|
@@ -199,6 +200,14 @@ const getCellOrValueType = (cellOrValue) => {
|
|
|
199
200
|
const isCellOrValueOrUndefined = (cellOrValue) =>
|
|
200
201
|
isUndefined(cellOrValue) || !isUndefined(getCellOrValueType(cellOrValue));
|
|
201
202
|
const isJsonType = (type) => type == OBJECT || type == ARRAY;
|
|
203
|
+
const isCellOrValueSchemaType = (type) =>
|
|
204
|
+
isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
|
|
205
|
+
const isCellOrValueSchemaTypes = (types) =>
|
|
206
|
+
isArray(types)
|
|
207
|
+
? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
|
|
208
|
+
: isCellOrValueSchemaType(types);
|
|
209
|
+
const cellOrValueSchemaTypeIncludes = (types, type) =>
|
|
210
|
+
isArray(types) ? arrayHas(types, type) : types == type;
|
|
202
211
|
const encodeIfJson = (value) =>
|
|
203
212
|
isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
|
|
204
213
|
const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
|
|
@@ -756,13 +765,29 @@ const createStore = () => {
|
|
|
756
765
|
const validateCellOrValueSchema = (schema) => {
|
|
757
766
|
if (
|
|
758
767
|
!objValidate(schema, (_child, id2) =>
|
|
759
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
768
|
+
arrayHas([TYPE, ENUM, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
760
769
|
)
|
|
761
770
|
) {
|
|
762
771
|
return false;
|
|
763
772
|
}
|
|
764
773
|
const type = schema[TYPE];
|
|
765
|
-
|
|
774
|
+
const enumValues = schema[ENUM];
|
|
775
|
+
if (
|
|
776
|
+
isUndefined(enumValues)
|
|
777
|
+
? !isCellOrValueSchemaTypes(type)
|
|
778
|
+
: !isUndefined(type) ||
|
|
779
|
+
!isArray(enumValues) ||
|
|
780
|
+
isUndefined(enumValues[0]) ||
|
|
781
|
+
!arrayEvery(enumValues, (enumValue) => {
|
|
782
|
+
const enumType = getCellOrValueType(enumValue);
|
|
783
|
+
return (
|
|
784
|
+
!isNull(enumValue) &&
|
|
785
|
+
!isUndefined(enumType) &&
|
|
786
|
+
!isJsonType(enumType) &&
|
|
787
|
+
!isReservedString(enumValue)
|
|
788
|
+
);
|
|
789
|
+
})
|
|
790
|
+
) {
|
|
766
791
|
return false;
|
|
767
792
|
}
|
|
768
793
|
const defaultValue = schema[DEFAULT];
|
|
@@ -771,7 +796,12 @@ const createStore = () => {
|
|
|
771
796
|
}
|
|
772
797
|
if (!isNull(defaultValue)) {
|
|
773
798
|
if (
|
|
774
|
-
|
|
799
|
+
(isUndefined(enumValues)
|
|
800
|
+
? !cellOrValueSchemaTypeIncludes(
|
|
801
|
+
type,
|
|
802
|
+
getCellOrValueType(defaultValue),
|
|
803
|
+
)
|
|
804
|
+
: !arrayHas(enumValues, defaultValue)) ||
|
|
775
805
|
isReservedString(defaultValue)
|
|
776
806
|
) {
|
|
777
807
|
objDel(schema, DEFAULT);
|
|
@@ -798,13 +828,15 @@ const createStore = () => {
|
|
|
798
828
|
isObject(tables) ? objMap(tables, cloneTable) : tables;
|
|
799
829
|
const cloneValues = (values) =>
|
|
800
830
|
isObject(values) ? objMap(values, getArg) : values;
|
|
801
|
-
const isValidEncodedJson = (cellOrValue,
|
|
831
|
+
const isValidEncodedJson = (cellOrValue, types) =>
|
|
802
832
|
acceptingEncodedData == 1 &&
|
|
803
833
|
isEncodedJson(cellOrValue) &&
|
|
804
834
|
tryReturn(() => {
|
|
805
835
|
const encodedType = getCellOrValueType(decodeIfJson(cellOrValue));
|
|
806
836
|
return (
|
|
807
|
-
isJsonType(encodedType) &&
|
|
837
|
+
isJsonType(encodedType) &&
|
|
838
|
+
(isUndefined(types) ||
|
|
839
|
+
cellOrValueSchemaTypeIncludes(types, encodedType))
|
|
808
840
|
);
|
|
809
841
|
}, false) == true;
|
|
810
842
|
const validateContent = isArray;
|
|
@@ -857,7 +889,8 @@ const createStore = () => {
|
|
|
857
889
|
: isReservedString(cell, acceptingEncodedData)
|
|
858
890
|
? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
|
|
859
891
|
: isEncodedJson(cell)
|
|
860
|
-
?
|
|
892
|
+
? isUndefined(cellSchema[ENUM]) &&
|
|
893
|
+
isValidEncodedJson(cell, cellSchema[TYPE])
|
|
861
894
|
? cell
|
|
862
895
|
: cellInvalid(
|
|
863
896
|
tableId,
|
|
@@ -866,23 +899,36 @@ const createStore = () => {
|
|
|
866
899
|
cell,
|
|
867
900
|
cellSchema[DEFAULT],
|
|
868
901
|
)
|
|
869
|
-
:
|
|
870
|
-
?
|
|
871
|
-
|
|
902
|
+
: isUndefined(cellSchema[ENUM])
|
|
903
|
+
? cellOrValueSchemaTypeIncludes(
|
|
904
|
+
cellSchema[TYPE],
|
|
905
|
+
getCellOrValueType(cell),
|
|
906
|
+
)
|
|
907
|
+
? encodeValid(cell, () =>
|
|
908
|
+
cellInvalid(
|
|
909
|
+
tableId,
|
|
910
|
+
rowId,
|
|
911
|
+
cellId,
|
|
912
|
+
cell,
|
|
913
|
+
cellSchema[DEFAULT],
|
|
914
|
+
),
|
|
915
|
+
)
|
|
916
|
+
: cellInvalid(
|
|
917
|
+
tableId,
|
|
918
|
+
rowId,
|
|
919
|
+
cellId,
|
|
920
|
+
cell,
|
|
921
|
+
cellSchema[DEFAULT],
|
|
922
|
+
)
|
|
923
|
+
: arrayHas(cellSchema[ENUM], cell)
|
|
924
|
+
? cell
|
|
925
|
+
: cellInvalid(
|
|
872
926
|
tableId,
|
|
873
927
|
rowId,
|
|
874
928
|
cellId,
|
|
875
929
|
cell,
|
|
876
930
|
cellSchema[DEFAULT],
|
|
877
931
|
),
|
|
878
|
-
)
|
|
879
|
-
: cellInvalid(
|
|
880
|
-
tableId,
|
|
881
|
-
rowId,
|
|
882
|
-
cellId,
|
|
883
|
-
cell,
|
|
884
|
-
cellSchema[DEFAULT],
|
|
885
|
-
),
|
|
886
932
|
() => cellInvalid(tableId, rowId, cellId, cell),
|
|
887
933
|
)
|
|
888
934
|
: isUndefined(getCellOrValueType(cell)) ||
|
|
@@ -927,14 +973,22 @@ const createStore = () => {
|
|
|
927
973
|
: isReservedString(value, acceptingEncodedData)
|
|
928
974
|
? valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
929
975
|
: isEncodedJson(value)
|
|
930
|
-
?
|
|
976
|
+
? isUndefined(valueSchema[ENUM]) &&
|
|
977
|
+
isValidEncodedJson(value, valueSchema[TYPE])
|
|
931
978
|
? value
|
|
932
979
|
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
933
|
-
:
|
|
934
|
-
?
|
|
935
|
-
|
|
980
|
+
: isUndefined(valueSchema[ENUM])
|
|
981
|
+
? cellOrValueSchemaTypeIncludes(
|
|
982
|
+
valueSchema[TYPE],
|
|
983
|
+
getCellOrValueType(value),
|
|
936
984
|
)
|
|
937
|
-
|
|
985
|
+
? encodeValid(value, () =>
|
|
986
|
+
valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
987
|
+
)
|
|
988
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
989
|
+
: arrayHas(valueSchema[ENUM], value)
|
|
990
|
+
? value
|
|
991
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
938
992
|
() => valueInvalid(valueId, value),
|
|
939
993
|
)
|
|
940
994
|
: isUndefined(getCellOrValueType(value)) ||
|
|
@@ -8,6 +8,7 @@ const FUNCTION = getTypeOf(getTypeOf);
|
|
|
8
8
|
const OBJECT = 'object';
|
|
9
9
|
const ARRAY = 'array';
|
|
10
10
|
const TYPE = 'type';
|
|
11
|
+
const ENUM = 'enum';
|
|
11
12
|
const DEFAULT = 'default';
|
|
12
13
|
const ALLOW_NULL = 'allowNull';
|
|
13
14
|
const NULL = 'null';
|
|
@@ -199,6 +200,14 @@ const getCellOrValueType = (cellOrValue) => {
|
|
|
199
200
|
const isCellOrValueOrUndefined = (cellOrValue) =>
|
|
200
201
|
isUndefined(cellOrValue) || !isUndefined(getCellOrValueType(cellOrValue));
|
|
201
202
|
const isJsonType = (type) => type == OBJECT || type == ARRAY;
|
|
203
|
+
const isCellOrValueSchemaType = (type) =>
|
|
204
|
+
isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
|
|
205
|
+
const isCellOrValueSchemaTypes = (types) =>
|
|
206
|
+
isArray(types)
|
|
207
|
+
? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
|
|
208
|
+
: isCellOrValueSchemaType(types);
|
|
209
|
+
const cellOrValueSchemaTypeIncludes = (types, type) =>
|
|
210
|
+
isArray(types) ? arrayHas(types, type) : types == type;
|
|
202
211
|
const encodeIfJson = (value) =>
|
|
203
212
|
isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
|
|
204
213
|
const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
|
|
@@ -756,13 +765,29 @@ const createStore = () => {
|
|
|
756
765
|
const validateCellOrValueSchema = (schema) => {
|
|
757
766
|
if (
|
|
758
767
|
!objValidate(schema, (_child, id2) =>
|
|
759
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
768
|
+
arrayHas([TYPE, ENUM, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
760
769
|
)
|
|
761
770
|
) {
|
|
762
771
|
return false;
|
|
763
772
|
}
|
|
764
773
|
const type = schema[TYPE];
|
|
765
|
-
|
|
774
|
+
const enumValues = schema[ENUM];
|
|
775
|
+
if (
|
|
776
|
+
isUndefined(enumValues)
|
|
777
|
+
? !isCellOrValueSchemaTypes(type)
|
|
778
|
+
: !isUndefined(type) ||
|
|
779
|
+
!isArray(enumValues) ||
|
|
780
|
+
isUndefined(enumValues[0]) ||
|
|
781
|
+
!arrayEvery(enumValues, (enumValue) => {
|
|
782
|
+
const enumType = getCellOrValueType(enumValue);
|
|
783
|
+
return (
|
|
784
|
+
!isNull(enumValue) &&
|
|
785
|
+
!isUndefined(enumType) &&
|
|
786
|
+
!isJsonType(enumType) &&
|
|
787
|
+
!isReservedString(enumValue)
|
|
788
|
+
);
|
|
789
|
+
})
|
|
790
|
+
) {
|
|
766
791
|
return false;
|
|
767
792
|
}
|
|
768
793
|
const defaultValue = schema[DEFAULT];
|
|
@@ -771,7 +796,12 @@ const createStore = () => {
|
|
|
771
796
|
}
|
|
772
797
|
if (!isNull(defaultValue)) {
|
|
773
798
|
if (
|
|
774
|
-
|
|
799
|
+
(isUndefined(enumValues)
|
|
800
|
+
? !cellOrValueSchemaTypeIncludes(
|
|
801
|
+
type,
|
|
802
|
+
getCellOrValueType(defaultValue),
|
|
803
|
+
)
|
|
804
|
+
: !arrayHas(enumValues, defaultValue)) ||
|
|
775
805
|
isReservedString(defaultValue)
|
|
776
806
|
) {
|
|
777
807
|
objDel(schema, DEFAULT);
|
|
@@ -798,13 +828,15 @@ const createStore = () => {
|
|
|
798
828
|
isObject(tables) ? objMap(tables, cloneTable) : tables;
|
|
799
829
|
const cloneValues = (values) =>
|
|
800
830
|
isObject(values) ? objMap(values, getArg) : values;
|
|
801
|
-
const isValidEncodedJson = (cellOrValue,
|
|
831
|
+
const isValidEncodedJson = (cellOrValue, types) =>
|
|
802
832
|
acceptingEncodedData == 1 &&
|
|
803
833
|
isEncodedJson(cellOrValue) &&
|
|
804
834
|
tryReturn(() => {
|
|
805
835
|
const encodedType = getCellOrValueType(decodeIfJson(cellOrValue));
|
|
806
836
|
return (
|
|
807
|
-
isJsonType(encodedType) &&
|
|
837
|
+
isJsonType(encodedType) &&
|
|
838
|
+
(isUndefined(types) ||
|
|
839
|
+
cellOrValueSchemaTypeIncludes(types, encodedType))
|
|
808
840
|
);
|
|
809
841
|
}, false) == true;
|
|
810
842
|
const validateContent = isArray;
|
|
@@ -857,7 +889,8 @@ const createStore = () => {
|
|
|
857
889
|
: isReservedString(cell, acceptingEncodedData)
|
|
858
890
|
? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
|
|
859
891
|
: isEncodedJson(cell)
|
|
860
|
-
?
|
|
892
|
+
? isUndefined(cellSchema[ENUM]) &&
|
|
893
|
+
isValidEncodedJson(cell, cellSchema[TYPE])
|
|
861
894
|
? cell
|
|
862
895
|
: cellInvalid(
|
|
863
896
|
tableId,
|
|
@@ -866,23 +899,36 @@ const createStore = () => {
|
|
|
866
899
|
cell,
|
|
867
900
|
cellSchema[DEFAULT],
|
|
868
901
|
)
|
|
869
|
-
:
|
|
870
|
-
?
|
|
871
|
-
|
|
902
|
+
: isUndefined(cellSchema[ENUM])
|
|
903
|
+
? cellOrValueSchemaTypeIncludes(
|
|
904
|
+
cellSchema[TYPE],
|
|
905
|
+
getCellOrValueType(cell),
|
|
906
|
+
)
|
|
907
|
+
? encodeValid(cell, () =>
|
|
908
|
+
cellInvalid(
|
|
909
|
+
tableId,
|
|
910
|
+
rowId,
|
|
911
|
+
cellId,
|
|
912
|
+
cell,
|
|
913
|
+
cellSchema[DEFAULT],
|
|
914
|
+
),
|
|
915
|
+
)
|
|
916
|
+
: cellInvalid(
|
|
917
|
+
tableId,
|
|
918
|
+
rowId,
|
|
919
|
+
cellId,
|
|
920
|
+
cell,
|
|
921
|
+
cellSchema[DEFAULT],
|
|
922
|
+
)
|
|
923
|
+
: arrayHas(cellSchema[ENUM], cell)
|
|
924
|
+
? cell
|
|
925
|
+
: cellInvalid(
|
|
872
926
|
tableId,
|
|
873
927
|
rowId,
|
|
874
928
|
cellId,
|
|
875
929
|
cell,
|
|
876
930
|
cellSchema[DEFAULT],
|
|
877
931
|
),
|
|
878
|
-
)
|
|
879
|
-
: cellInvalid(
|
|
880
|
-
tableId,
|
|
881
|
-
rowId,
|
|
882
|
-
cellId,
|
|
883
|
-
cell,
|
|
884
|
-
cellSchema[DEFAULT],
|
|
885
|
-
),
|
|
886
932
|
() => cellInvalid(tableId, rowId, cellId, cell),
|
|
887
933
|
)
|
|
888
934
|
: isUndefined(getCellOrValueType(cell)) ||
|
|
@@ -927,14 +973,22 @@ const createStore = () => {
|
|
|
927
973
|
: isReservedString(value, acceptingEncodedData)
|
|
928
974
|
? valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
929
975
|
: isEncodedJson(value)
|
|
930
|
-
?
|
|
976
|
+
? isUndefined(valueSchema[ENUM]) &&
|
|
977
|
+
isValidEncodedJson(value, valueSchema[TYPE])
|
|
931
978
|
? value
|
|
932
979
|
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
933
|
-
:
|
|
934
|
-
?
|
|
935
|
-
|
|
980
|
+
: isUndefined(valueSchema[ENUM])
|
|
981
|
+
? cellOrValueSchemaTypeIncludes(
|
|
982
|
+
valueSchema[TYPE],
|
|
983
|
+
getCellOrValueType(value),
|
|
936
984
|
)
|
|
937
|
-
|
|
985
|
+
? encodeValid(value, () =>
|
|
986
|
+
valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
987
|
+
)
|
|
988
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
989
|
+
: arrayHas(valueSchema[ENUM], value)
|
|
990
|
+
? value
|
|
991
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
938
992
|
() => valueInvalid(valueId, value),
|
|
939
993
|
)
|
|
940
994
|
: isUndefined(getCellOrValueType(value)) ||
|