lib0 1.0.0-rc.1 → 1.0.0-rc.2
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/package.json +2 -2
- package/src/delta/delta.js +103 -156
- package/src/environment.js +2 -3
- package/src/schema.js +25 -39
- package/src/testing.js +1 -1
- package/src/ts.js +11 -2
- package/types/delta/binding.d.ts +0 -1
- package/types/delta/delta.d.ts +146 -177
- package/types/schema.d.ts +14 -15
- package/types/testing.d.ts +1 -1
- package/types/ts.d.ts +7 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lib0",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -282,7 +282,7 @@
|
|
|
282
282
|
"test:bundle": "esbuild bundle.test.js --bundle --outfile=dist/bundle.test.js --analyze --minify && wc -c dist/bundle.test.js",
|
|
283
283
|
"trace-deopt": "clear && node --trace-deopt src/test.js",
|
|
284
284
|
"trace-opt": "clear && node --trace-opt src/test.js",
|
|
285
|
-
"lint": "
|
|
285
|
+
"lint": "tsc && standard",
|
|
286
286
|
"gendocs": "node ./bin/gendocs.js",
|
|
287
287
|
"np": "np --test-script dist",
|
|
288
288
|
"version": "npm run clean && npm run dist && git add README.md",
|
package/src/delta/delta.js
CHANGED
|
@@ -317,7 +317,7 @@ export class InsertOp extends list.ListNode {
|
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
/**
|
|
320
|
-
* @template {DeltaConf} [
|
|
320
|
+
* @template {DeltaConf} [Conf={}]
|
|
321
321
|
*/
|
|
322
322
|
export class DeleteOp extends list.ListNode {
|
|
323
323
|
/**
|
|
@@ -327,7 +327,7 @@ export class DeleteOp extends list.ListNode {
|
|
|
327
327
|
super()
|
|
328
328
|
this.delete = len
|
|
329
329
|
/**
|
|
330
|
-
* @type {Delta<
|
|
330
|
+
* @type {Delta<Conf>?}
|
|
331
331
|
*/
|
|
332
332
|
this.prevValue = null
|
|
333
333
|
/**
|
|
@@ -666,13 +666,13 @@ export class SetAttrOp {
|
|
|
666
666
|
|
|
667
667
|
toJSON () {
|
|
668
668
|
const v = this.value
|
|
669
|
-
const prevValue = this.prevValue
|
|
670
669
|
const attribution = this.attribution
|
|
671
670
|
return object.assign({
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
671
|
+
type: this.type,
|
|
672
|
+
value: $deltaAny.check(v) ? v.toJSON() : v
|
|
673
|
+
},
|
|
674
|
+
attribution != null ? { attribution } : {}
|
|
675
|
+
)}
|
|
676
676
|
|
|
677
677
|
/**
|
|
678
678
|
* @param {SetAttrOp<V>} other
|
|
@@ -738,9 +738,12 @@ export class DeleteAttrOp {
|
|
|
738
738
|
*/
|
|
739
739
|
toJSON () {
|
|
740
740
|
const {
|
|
741
|
-
type, attribution,
|
|
741
|
+
type, attribution,
|
|
742
742
|
} = this
|
|
743
|
-
return object.assign(
|
|
743
|
+
return object.assign(
|
|
744
|
+
{ type },
|
|
745
|
+
attribution != null ? { attribution } : {}
|
|
746
|
+
)
|
|
744
747
|
}
|
|
745
748
|
|
|
746
749
|
/**
|
|
@@ -880,7 +883,7 @@ export const $modifyAttrOpWith = $content => s.$custom(o => $modifyAttrOp.check(
|
|
|
880
883
|
* @template {{[Key in string|number]: any}} Attrs
|
|
881
884
|
* @template {string|number} Key
|
|
882
885
|
* @template {any} Val
|
|
883
|
-
* @typedef {{ [K in (Key | keyof Attrs)]: (unknown extends Attrs[K] ? never : Attrs[K]) | (Key extends K ? Val : never) }} AddToAttrs
|
|
886
|
+
* @typedef {{ [K in (Key | keyof Attrs)]: (unknown extends Attrs[K] ? never : Attrs[K]) | (Key extends K ? Val : never) } & {}} AddToAttrs
|
|
884
887
|
*/
|
|
885
888
|
|
|
886
889
|
/**
|
|
@@ -903,72 +906,68 @@ export const $modifyAttrOpWith = $content => s.$custom(o => $modifyAttrOp.check(
|
|
|
903
906
|
* @property {fingerprintTrait.Fingerprintable} [DeltaConf.children=never]
|
|
904
907
|
* @property {boolean} [DeltaConf.text=never]
|
|
905
908
|
* @property {{[K:string|number]:fingerprintTrait.Fingerprintable}} [DeltaConf.attrs={}]
|
|
906
|
-
* @property {boolean} [DeltaConf.fixed=never]
|
|
907
909
|
* @property {boolean} [DeltaConf.recursiveChildren=false]
|
|
908
910
|
* @property {boolean} [DeltaConf.recursiveAttrs=false]
|
|
909
911
|
*/
|
|
910
912
|
|
|
911
913
|
/**
|
|
912
|
-
* @template {DeltaConf}
|
|
913
|
-
* @typedef {
|
|
914
|
-
*/
|
|
915
|
-
|
|
916
|
-
/**
|
|
917
|
-
* @template {DeltaConf} DConf
|
|
918
|
-
* @typedef {(DConf extends {children:infer Children} ? (unknown extends Children ? any : Children) : never) | (DConf extends {recursiveChildren:true} ? Delta<DConf> : never)} DeltaConfGetChildren
|
|
914
|
+
* @template {DeltaConf} Conf
|
|
915
|
+
* @typedef {Conf extends {name:infer Name} ? (unknown extends Name ? any : (Exclude<Name,undefined>)) : any} DeltaConfGetName
|
|
919
916
|
*/
|
|
920
917
|
|
|
921
918
|
/**
|
|
922
|
-
* @template {DeltaConf}
|
|
923
|
-
* @typedef {
|
|
919
|
+
* @template {DeltaConf} Conf
|
|
920
|
+
* @typedef {(Conf extends {children:infer Children} ? (unknown extends Children ? any : Children) : never) | (Conf extends {recursiveChildren:true} ? Delta<Conf> : never)} DeltaConfGetChildren
|
|
924
921
|
*/
|
|
925
922
|
|
|
926
923
|
/**
|
|
927
|
-
* @template {DeltaConf}
|
|
928
|
-
* @
|
|
924
|
+
* @template {DeltaConf} Conf
|
|
925
|
+
* @template {boolean} FixedConf
|
|
926
|
+
* @typedef {FixedConf extends true ? DeltaConfGetChildren<Conf> : any } DeltaConfGetAllowedChildren
|
|
929
927
|
*/
|
|
930
928
|
|
|
931
929
|
/**
|
|
932
|
-
* @template {DeltaConf}
|
|
933
|
-
* @typedef {
|
|
930
|
+
* @template {DeltaConf} Conf
|
|
931
|
+
* @typedef {0 extends (1 & Conf) ? string : (Conf extends {text:true} ? string : never)} DeltaConfGetText
|
|
934
932
|
*/
|
|
935
933
|
|
|
936
934
|
/**
|
|
937
|
-
* @template {DeltaConf}
|
|
938
|
-
* @typedef {
|
|
935
|
+
* @template {DeltaConf} Conf
|
|
936
|
+
* @typedef {import('../ts.js').TypeIsAny<Conf, {[K:string|number]:any}, (Conf extends {attrs:infer Attrs} ? (Attrs extends undefined ? {} : Attrs) : {})>} DeltaConfGetAttrs
|
|
939
937
|
*/
|
|
940
938
|
|
|
941
939
|
/**
|
|
942
|
-
* @template {DeltaConf}
|
|
943
|
-
* @
|
|
940
|
+
* @template {DeltaConf} Conf
|
|
941
|
+
* @template {boolean} FixedConf
|
|
942
|
+
* @typedef {FixedConf extends true ? DeltaConfGetAttrs<Conf> : {[K:string|number]:any}} DeltaConfGetAllowedAttrs
|
|
944
943
|
*/
|
|
945
944
|
|
|
946
945
|
/**
|
|
947
|
-
* @template {DeltaConf}
|
|
948
|
-
* @typedef {
|
|
946
|
+
* @template {DeltaConf} Conf
|
|
947
|
+
* @typedef {Conf extends {recursiveChildren:true} ? true : false} DeltaConfGetRecursiveChildren
|
|
949
948
|
*/
|
|
950
949
|
|
|
951
950
|
/**
|
|
952
|
-
* @template {DeltaConf}
|
|
953
|
-
* @typedef {
|
|
951
|
+
* @template {DeltaConf} Conf
|
|
952
|
+
* @typedef {Conf extends {recursiveAttrs:true} ? true : false} DeltaConfigGetRecursiveAttrs
|
|
954
953
|
*/
|
|
955
954
|
|
|
956
955
|
/**
|
|
957
956
|
* Transform Delta(Builder) to a normal delta.
|
|
958
957
|
*
|
|
959
958
|
* @template V
|
|
960
|
-
* @typedef {V extends never ? never : (import('../ts.js').TypeIsAny<V,any,V extends Delta<infer
|
|
959
|
+
* @typedef {V extends never ? never : (import('../ts.js').TypeIsAny<V,any,V extends Delta<infer Conf> ? Delta<Conf> : V>)} _SanifyDelta
|
|
961
960
|
*/
|
|
962
961
|
|
|
963
962
|
/**
|
|
964
|
-
* @template {DeltaConf}
|
|
965
|
-
* @typedef {import('../ts.js').Prettify<{[K in keyof
|
|
963
|
+
* @template {DeltaConf} Conf
|
|
964
|
+
* @typedef {import('../ts.js').Prettify<{[K in keyof Conf]: K extends 'attrs' ? import('../ts.js').Prettify<{ [KA in keyof Conf[K]]: _SanifyDelta<Conf[K][KA]> },1> : (K extends 'children' ? _SanifyDelta<Conf[K]> : Conf[K]) }, 1>} PrettifyDeltaConf
|
|
966
965
|
*/
|
|
967
966
|
|
|
968
967
|
/**
|
|
969
968
|
* @template {DeltaConf} D1
|
|
970
|
-
* @template
|
|
971
|
-
* @typedef {import('../ts.js').TypeIsAny<D1, any, PrettifyDeltaConf<{[K in (keyof D1|keyof D2)]: K extends keyof D2 ? D2[K] : (K extends keyof D1 ? D1[K] : never)}>>} DeltaConfOverwrite
|
|
969
|
+
* @template D2
|
|
970
|
+
* @typedef {(import('../ts.js').TypeIsAny<D1, any, PrettifyDeltaConf<{[K in (keyof D1|keyof D2)]: K extends keyof D2 ? D2[K] : (K extends keyof D1 ? D1[K] : never)}>> & {}) extends infer DC extends DeltaConf ? DC : never} DeltaConfOverwrite
|
|
972
971
|
*/
|
|
973
972
|
|
|
974
973
|
/**
|
|
@@ -1019,12 +1018,12 @@ class DeltaData {
|
|
|
1019
1018
|
}
|
|
1020
1019
|
|
|
1021
1020
|
/**
|
|
1022
|
-
* @template {DeltaConf} [
|
|
1021
|
+
* @template {DeltaConf} [Conf={}]
|
|
1023
1022
|
* @extends {DeltaData<
|
|
1024
|
-
* DeltaConfGetName<
|
|
1025
|
-
* DeltaConfGetAttrs<
|
|
1026
|
-
* DeltaConfGetChildren<
|
|
1027
|
-
*
|
|
1023
|
+
* DeltaConfGetName<Conf>,
|
|
1024
|
+
* DeltaConfGetAttrs<Conf>,
|
|
1025
|
+
* DeltaConfGetChildren<Conf>,
|
|
1026
|
+
* Conf extends {text:true} ? true : false
|
|
1028
1027
|
* >}
|
|
1029
1028
|
*/
|
|
1030
1029
|
export class Delta extends DeltaData {
|
|
@@ -1137,7 +1136,7 @@ export class Delta extends DeltaData {
|
|
|
1137
1136
|
* formats&attributions). In the future, there might be additional merge operations that can be
|
|
1138
1137
|
* performed to result in smaller deltas. Set `markAsDone=false` to only perform the cleanup.
|
|
1139
1138
|
*
|
|
1140
|
-
* @return {Delta<
|
|
1139
|
+
* @return {Delta<Conf>}
|
|
1141
1140
|
*/
|
|
1142
1141
|
done (markAsDone = true) {
|
|
1143
1142
|
if (!this.isDone) {
|
|
@@ -1153,12 +1152,12 @@ export class Delta extends DeltaData {
|
|
|
1153
1152
|
}
|
|
1154
1153
|
|
|
1155
1154
|
/**
|
|
1156
|
-
* @template {DeltaConf}
|
|
1157
|
-
* @param {Delta<
|
|
1155
|
+
* @template {DeltaConf} Conf
|
|
1156
|
+
* @param {Delta<Conf>} d
|
|
1158
1157
|
* @param {number} start
|
|
1159
1158
|
* @param {number} end
|
|
1160
1159
|
* @param {ChildrenOpAny?} currNode - start slicing at this node (instead of d.children.start)
|
|
1161
|
-
* @return {DeltaBuilder<
|
|
1160
|
+
* @return {DeltaBuilder<Conf>}
|
|
1162
1161
|
*/
|
|
1163
1162
|
export const slice = (d, start = 0, end = d.childCnt, currNode = d.children.start) => {
|
|
1164
1163
|
const cpy = /** @type {DeltaAny} */ (new DeltaBuilder(d.name, d.$schema))
|
|
@@ -1204,7 +1203,7 @@ export const slice = (d, start = 0, end = d.childCnt, currNode = d.children.star
|
|
|
1204
1203
|
/**
|
|
1205
1204
|
* @template {DeltaAny} D
|
|
1206
1205
|
* @param {D} d
|
|
1207
|
-
* @return {D extends Delta<infer
|
|
1206
|
+
* @return {D extends Delta<infer Conf> ? DeltaBuilder<Conf> : never}
|
|
1208
1207
|
*/
|
|
1209
1208
|
export const clone = d => /** @type {any} */ (slice(d, 0, d.childCnt))
|
|
1210
1209
|
|
|
@@ -1256,13 +1255,14 @@ const modDeltaCheck = d => {
|
|
|
1256
1255
|
}
|
|
1257
1256
|
|
|
1258
1257
|
/**
|
|
1259
|
-
* @template {DeltaConf} [
|
|
1260
|
-
* @
|
|
1258
|
+
* @template {DeltaConf} [Conf={}]
|
|
1259
|
+
* @template {boolean} [FixedConf=false]
|
|
1260
|
+
* @extends {Delta<Conf>}
|
|
1261
1261
|
*/
|
|
1262
1262
|
export class DeltaBuilder extends Delta {
|
|
1263
1263
|
/**
|
|
1264
1264
|
* @param {string?} name
|
|
1265
|
-
* @param {s.Schema<Delta<
|
|
1265
|
+
* @param {s.Schema<Delta<Conf>>?} $schema
|
|
1266
1266
|
*/
|
|
1267
1267
|
constructor (name, $schema) {
|
|
1268
1268
|
super(name, $schema)
|
|
@@ -1335,14 +1335,14 @@ export class DeltaBuilder extends Delta {
|
|
|
1335
1335
|
}
|
|
1336
1336
|
|
|
1337
1337
|
/**
|
|
1338
|
-
* @template {(
|
|
1338
|
+
* @template {(FixedConf extends true ? never : (Array<any>|string)) | (DeltaConfGetChildren<Conf> extends infer Children ? (Children extends never ? never : Array<Children>) : never) | DeltaConfGetText<Conf>} NewContent
|
|
1339
1339
|
* @param {NewContent} insert
|
|
1340
1340
|
* @param {FormattingAttributes?} [formatting]
|
|
1341
1341
|
* @param {Attribution?} [attribution]
|
|
1342
|
-
* @return {DeltaBuilder<
|
|
1342
|
+
* @return {DeltaBuilder<FixedConf extends true ? Conf : DeltaConfOverwrite<Conf,
|
|
1343
1343
|
* (Exclude<NewContent,string> extends never ? {} : {
|
|
1344
|
-
* children: Exclude<NewContent,string>[number]|DeltaConfGetChildren<
|
|
1345
|
-
* }) & (Extract<NewContent,string> extends never ? {} : { text: true })
|
|
1344
|
+
* children: Exclude<NewContent,string>[number]|DeltaConfGetChildren<Conf>
|
|
1345
|
+
* }) & (Extract<NewContent,string> extends never ? {} : { text: true })>, FixedConf>}
|
|
1346
1346
|
*/
|
|
1347
1347
|
insert (insert, formatting = null, attribution = null) {
|
|
1348
1348
|
modDeltaCheck(this)
|
|
@@ -1374,11 +1374,11 @@ export class DeltaBuilder extends Delta {
|
|
|
1374
1374
|
}
|
|
1375
1375
|
|
|
1376
1376
|
/**
|
|
1377
|
-
* @template {Extract<DeltaConfGetAllowedChildren<
|
|
1377
|
+
* @template {Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>,Delta>} NewContent
|
|
1378
1378
|
* @param {NewContent} modify
|
|
1379
1379
|
* @param {FormattingAttributes?} formatting
|
|
1380
1380
|
* @param {Attribution?} attribution
|
|
1381
|
-
* @return {DeltaBuilder<DeltaConfOverwrite<
|
|
1381
|
+
* @return {DeltaBuilder<DeltaConfOverwrite<Conf, {children: DeltaConfGetChildren<Conf>|NewContent}>, FixedConf>}
|
|
1382
1382
|
*/
|
|
1383
1383
|
modify (modify, formatting = null, attribution = null) {
|
|
1384
1384
|
modDeltaCheck(this)
|
|
@@ -1425,13 +1425,13 @@ export class DeltaBuilder extends Delta {
|
|
|
1425
1425
|
}
|
|
1426
1426
|
|
|
1427
1427
|
/**
|
|
1428
|
-
* @template {keyof DeltaConfGetAllowedAttrs<
|
|
1429
|
-
* @template {DeltaConfGetAllowedAttrs<
|
|
1428
|
+
* @template {Extract<keyof DeltaConfGetAllowedAttrs<Conf, FixedConf>,string|number>} Key
|
|
1429
|
+
* @template {DeltaConfGetAllowedAttrs<Conf, FixedConf>[Key]} Val
|
|
1430
1430
|
* @param {Key} key
|
|
1431
1431
|
* @param {Val} val
|
|
1432
1432
|
* @param {Attribution?} attribution
|
|
1433
1433
|
* @param {Val|undefined} [prevValue]
|
|
1434
|
-
* @return {DeltaBuilder<DeltaConfOverwrite<
|
|
1434
|
+
* @return {DeltaBuilder<DeltaConfOverwrite<Conf,{attrs:AddToAttrs<DeltaConfGetAttrs<Conf>,Key,Val>}>, FixedConf>}
|
|
1435
1435
|
*/
|
|
1436
1436
|
setAttr (key, val, attribution = null, prevValue) {
|
|
1437
1437
|
modDeltaCheck(this)
|
|
@@ -1442,13 +1442,13 @@ export class DeltaBuilder extends Delta {
|
|
|
1442
1442
|
}
|
|
1443
1443
|
|
|
1444
1444
|
/**
|
|
1445
|
-
* @template {DeltaConfGetAllowedAttrs<
|
|
1445
|
+
* @template {DeltaConfGetAllowedAttrs<Conf, FixedConf>} NewAttrs
|
|
1446
1446
|
* @param {NewAttrs} attrs
|
|
1447
1447
|
* @param {Attribution?} attribution
|
|
1448
1448
|
* @return {DeltaBuilder<DeltaConfOverwrite<
|
|
1449
|
-
*
|
|
1450
|
-
* { attrs: MergeAttrs<DeltaConfGetAttrs<
|
|
1451
|
-
*
|
|
1449
|
+
* Conf,
|
|
1450
|
+
* { attrs: MergeAttrs<DeltaConfGetAttrs<Conf>,NewAttrs> }
|
|
1451
|
+
* >, FixedConf>
|
|
1452
1452
|
* }
|
|
1453
1453
|
*/
|
|
1454
1454
|
setAttrs (attrs, attribution = null) {
|
|
@@ -1460,13 +1460,13 @@ export class DeltaBuilder extends Delta {
|
|
|
1460
1460
|
}
|
|
1461
1461
|
|
|
1462
1462
|
/**
|
|
1463
|
-
* @template {keyof DeltaConfGetAllowedAttrs<
|
|
1463
|
+
* @template {Extract<keyof DeltaConfGetAllowedAttrs<Conf, FixedConf>,string|number>} Key
|
|
1464
1464
|
* @param {Key} key
|
|
1465
1465
|
* @param {Attribution?} attribution
|
|
1466
1466
|
* @param {any} [prevValue]
|
|
1467
|
-
* @return {DeltaBuilder<DeltaConfOverwrite<
|
|
1468
|
-
* attrs: AddToAttrs<DeltaConfGetAttrs<
|
|
1469
|
-
* }
|
|
1467
|
+
* @return {DeltaBuilder<DeltaConfOverwrite<Conf, {
|
|
1468
|
+
* attrs: AddToAttrs<DeltaConfGetAttrs<Conf>,Key,never>
|
|
1469
|
+
* }>, FixedConf>}
|
|
1470
1470
|
*/
|
|
1471
1471
|
deleteAttr (key, attribution = null, prevValue) {
|
|
1472
1472
|
modDeltaCheck(this)
|
|
@@ -1477,11 +1477,11 @@ export class DeltaBuilder extends Delta {
|
|
|
1477
1477
|
}
|
|
1478
1478
|
|
|
1479
1479
|
/**
|
|
1480
|
-
* @template {DeltaConfGetAllowedAttrs<
|
|
1481
|
-
* @template {Extract<DeltaConfGetAllowedAttrs<
|
|
1480
|
+
* @template {DeltaConfGetAllowedAttrs<Conf, FixedConf> extends infer As ? { [K in keyof As]: Extract<As[K],DeltaAny> extends never ? never : K }[keyof As] : never} Key
|
|
1481
|
+
* @template {Extract<DeltaConfGetAllowedAttrs<Conf, FixedConf>[Key],DeltaAny>} D
|
|
1482
1482
|
* @param {Key} key
|
|
1483
1483
|
* @param {D} modify
|
|
1484
|
-
* @return {DeltaBuilder<DeltaConfOverwrite<
|
|
1484
|
+
* @return {DeltaBuilder<DeltaConfOverwrite<Conf,{attrs:AddToAttrs<DeltaConfGetAttrs<Conf>,Key,D>}>, FixedConf>}
|
|
1485
1485
|
*/
|
|
1486
1486
|
modifyAttr (key, modify) {
|
|
1487
1487
|
modDeltaCheck(this)
|
|
@@ -1490,7 +1490,7 @@ export class DeltaBuilder extends Delta {
|
|
|
1490
1490
|
}
|
|
1491
1491
|
|
|
1492
1492
|
/**
|
|
1493
|
-
* @param {Delta<
|
|
1493
|
+
* @param {Delta<Conf>} other
|
|
1494
1494
|
*/
|
|
1495
1495
|
apply (other) {
|
|
1496
1496
|
modDeltaCheck(this)
|
|
@@ -1848,15 +1848,13 @@ export class DeltaBuilder extends Delta {
|
|
|
1848
1848
|
*
|
|
1849
1849
|
* delta.create().insert('a').append(delta.create().insert('b')) // => insert "ab"
|
|
1850
1850
|
*
|
|
1851
|
-
* @todo on fixed deltas this should not extend
|
|
1852
|
-
*
|
|
1853
1851
|
* @template {DeltaConf} OtherDeltaConf
|
|
1854
1852
|
* @param {Delta<OtherDeltaConf>} other
|
|
1855
|
-
* @return {DeltaBuilder<DeltaConfOverwrite<
|
|
1856
|
-
*
|
|
1857
|
-
* (DeltaConfGetChildren<OtherDeltaConf> extends never ? {} : { children: DeltaConfGetChildren<
|
|
1853
|
+
* @return {DeltaBuilder<FixedConf extends true ? Conf : DeltaConfOverwrite<
|
|
1854
|
+
* Conf,
|
|
1855
|
+
* (DeltaConfGetChildren<OtherDeltaConf> extends never ? {} : { children: DeltaConfGetChildren<Conf> | DeltaConfGetChildren<OtherDeltaConf> })
|
|
1858
1856
|
* & (DeltaConfGetText<OtherDeltaConf> extends string ? { text: true } : never)
|
|
1859
|
-
*
|
|
1857
|
+
* >, FixedConf>}
|
|
1860
1858
|
*/
|
|
1861
1859
|
append (other) {
|
|
1862
1860
|
const children = this.children
|
|
@@ -1894,8 +1892,8 @@ const updateOpFormat = (op, formatUpdate) => {
|
|
|
1894
1892
|
}
|
|
1895
1893
|
|
|
1896
1894
|
/**
|
|
1897
|
-
* @template {DeltaConf}
|
|
1898
|
-
* @extends {s.Schema<Delta<
|
|
1895
|
+
* @template {DeltaConf} Conf
|
|
1896
|
+
* @extends {s.Schema<Delta<Conf>>}
|
|
1899
1897
|
*/
|
|
1900
1898
|
export class $Delta extends s.Schema {
|
|
1901
1899
|
/**
|
|
@@ -1915,11 +1913,11 @@ export class $Delta extends s.Schema {
|
|
|
1915
1913
|
}
|
|
1916
1914
|
/**
|
|
1917
1915
|
* @type {{
|
|
1918
|
-
* $name: s.Schema<DeltaConfGetName<
|
|
1919
|
-
* $attrs: s.Schema<DeltaConfGetAttrs<
|
|
1920
|
-
* $children: s.Schema<DeltaConfGetChildren<
|
|
1921
|
-
* hasText: DeltaConfGetText<
|
|
1922
|
-
* recursiveChildren: DeltaConfGetRecursiveChildren<
|
|
1916
|
+
* $name: s.Schema<DeltaConfGetName<Conf>>,
|
|
1917
|
+
* $attrs: s.Schema<DeltaConfGetAttrs<Conf>>,
|
|
1918
|
+
* $children: s.Schema<DeltaConfGetChildren<Conf>>,
|
|
1919
|
+
* hasText: DeltaConfGetText<Conf>
|
|
1920
|
+
* recursiveChildren: DeltaConfGetRecursiveChildren<Conf>,
|
|
1923
1921
|
* $formats: s.Schema<{[K:string]:any}>
|
|
1924
1922
|
* }}
|
|
1925
1923
|
*/
|
|
@@ -1929,7 +1927,7 @@ export class $Delta extends s.Schema {
|
|
|
1929
1927
|
/**
|
|
1930
1928
|
* @param {any} o
|
|
1931
1929
|
* @param {s.ValidationError} [err]
|
|
1932
|
-
* @return {o is Delta<
|
|
1930
|
+
* @return {o is Delta<Conf>}
|
|
1933
1931
|
*/
|
|
1934
1932
|
check (o, err = undefined) {
|
|
1935
1933
|
const { $name, $attrs, $children, hasText, $formats } = this.shape
|
|
@@ -1962,13 +1960,11 @@ export class $Delta extends s.Schema {
|
|
|
1962
1960
|
* @param {HasText} [opts.text] Whether this delta contains text using `textOp`
|
|
1963
1961
|
* @param {Formats} [opts.formats]
|
|
1964
1962
|
* @param {RecursiveChildren} [opts.recursiveChildren]
|
|
1965
|
-
* @return {[s.
|
|
1966
|
-
*
|
|
1967
|
-
*
|
|
1968
|
-
*
|
|
1969
|
-
*
|
|
1970
|
-
* recursiveChildren: RecursiveChildren
|
|
1971
|
-
* }>> : never}
|
|
1963
|
+
* @return {[s.ReadSchemaUnwrapped<NodeNameSchema>,s.ReadSchemaUnwrapped<AttrsSchema>,s.ReadSchemaUnwrapped<ChildrenSchema>] extends [infer NodeName, infer Attrs, infer Children] ? s.Schema<Delta<PrettifyDeltaConf<(import('../ts.js').TypeIsAny<NodeName, {}, { name: NodeName }> &
|
|
1964
|
+
* ({} extends Attrs ? {} : { attrs: Attrs }) &
|
|
1965
|
+
* ([Children] extends [never] ? {} : { children: Children }) &
|
|
1966
|
+
* (HasText extends false ? {} : { text: HasText }) &
|
|
1967
|
+
* (RecursiveChildren extends false ? {} : { recursiveChildren: RecursiveChildren })) extends infer DC extends DeltaConf ? DC : never>>> : never}
|
|
1972
1968
|
*/
|
|
1973
1969
|
export const $delta = ({ name, attrs, children, text, formats, recursiveChildren: recursive }) => /** @type {any} */ (new $Delta(
|
|
1974
1970
|
/** @type {any} */ (name == null ? s.$any : s.$(name)),
|
|
@@ -1981,55 +1977,6 @@ export const $delta = ({ name, attrs, children, text, formats, recursiveChildren
|
|
|
1981
1977
|
|
|
1982
1978
|
export const $$delta = /* @__PURE__ */s.$constructedBy($Delta)
|
|
1983
1979
|
|
|
1984
|
-
/**
|
|
1985
|
-
* @todo remove this
|
|
1986
|
-
*
|
|
1987
|
-
* @template {s.Schema<string>|string|Array<string>} [NodeNameSchema=s.Schema<any>]
|
|
1988
|
-
* @template {s.Schema<{ [key: string|number]: any }>|{ [key:string|number]:any }} [AttrsSchema=s.Schema<{}>]
|
|
1989
|
-
* @template {any} [ChildrenSchema=s.Schema<never>]
|
|
1990
|
-
* @template {boolean} [HasText=false]
|
|
1991
|
-
* @template {boolean} [Recursive=false]
|
|
1992
|
-
* @param {object} opts
|
|
1993
|
-
* @param {NodeNameSchema?} [opts.name]
|
|
1994
|
-
* @param {AttrsSchema?} [opts.attrs]
|
|
1995
|
-
* @param {ChildrenSchema?} [opts.children]
|
|
1996
|
-
* @param {HasText} [opts.text]
|
|
1997
|
-
* @param {Recursive} [opts.recursive]
|
|
1998
|
-
* @return {[s.Unwrap<s.ReadSchema<NodeNameSchema>>,s.Unwrap<s.ReadSchema<AttrsSchema>>,s.Unwrap<s.ReadSchema<ChildrenSchema>>] extends [infer NodeName, infer Attrs, infer Children] ? s.Schema<Delta<
|
|
1999
|
-
* NodeName,
|
|
2000
|
-
* Attrs,
|
|
2001
|
-
* Children|(Recursive extends true ? RecursiveDelta<NodeName,Attrs,Children,HasText extends true ? string : never> : never),
|
|
2002
|
-
* HasText extends true ? string : never
|
|
2003
|
-
* >> : never}
|
|
2004
|
-
*/
|
|
2005
|
-
export const _$delta = ({ name, attrs, children, text, recursive }) => {
|
|
2006
|
-
/**
|
|
2007
|
-
* @type {s.Schema<Array<any>>}
|
|
2008
|
-
*/
|
|
2009
|
-
let $arrContent = children == null ? s.$never : s.$array(s.$(children))
|
|
2010
|
-
const $name = name == null ? s.$any : s.$(name)
|
|
2011
|
-
const $attrsPartial = attrs == null ? s.$object({}) : (s.$$record.check(attrs) ? attrs : /** @type {any} */ (s.$(attrs)).partial)
|
|
2012
|
-
const $d = s.$custom(d => {
|
|
2013
|
-
if (
|
|
2014
|
-
!$deltaAny.check(d) ||
|
|
2015
|
-
!$name.check(d.name) ||
|
|
2016
|
-
object.some(d.attrs,
|
|
2017
|
-
(op, k) => $setAttrOp.check(op) && !$attrsPartial.check({ [k]: op.value })
|
|
2018
|
-
)
|
|
2019
|
-
) return false
|
|
2020
|
-
for (const op of d.children) {
|
|
2021
|
-
if ((!text && $textOp.check(op)) || ($insertOp.check(op) && !$arrContent.check(op.insert))) {
|
|
2022
|
-
return false
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
return true
|
|
2026
|
-
})
|
|
2027
|
-
if (recursive) {
|
|
2028
|
-
$arrContent = children == null ? s.$array($d) : s.$array(s.$(children), $d)
|
|
2029
|
-
}
|
|
2030
|
-
return /** @type {any} */ ($d)
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
1980
|
export const $deltaAny = /** @type {s.Schema<DeltaAny>} */ (/* @__PURE__ */s.$type('delta'))
|
|
2034
1981
|
export const $deltaBuilderAny = /** @type {s.Schema<DeltaBuilderAny>} */ (/* @__PURE__ */s.$custom(o => $deltaAny.check(o) && !o.isDone))
|
|
2035
1982
|
|
|
@@ -2060,10 +2007,10 @@ export const mergeDeltas = (a, b) => {
|
|
|
2060
2007
|
}
|
|
2061
2008
|
|
|
2062
2009
|
/**
|
|
2063
|
-
* @template {DeltaConf}
|
|
2010
|
+
* @template {DeltaConf} Conf
|
|
2064
2011
|
* @param {prng.PRNG} gen
|
|
2065
|
-
* @param {s.Schema<Delta<
|
|
2066
|
-
* @return {DeltaBuilder<
|
|
2012
|
+
* @param {s.Schema<Delta<Conf>>} $d
|
|
2013
|
+
* @return {DeltaBuilder<Conf>}
|
|
2067
2014
|
*/
|
|
2068
2015
|
export const random = (gen, $d) => {
|
|
2069
2016
|
const { $name, $attrs, $children, hasText, $formats: $formats_ } = /** @type {$Delta<any>} */ (/** @type {any} */ ($d)).shape
|
|
@@ -2100,17 +2047,17 @@ export const random = (gen, $d) => {
|
|
|
2100
2047
|
*/
|
|
2101
2048
|
/**
|
|
2102
2049
|
* @template {string} NodeName
|
|
2103
|
-
* @template {
|
|
2050
|
+
* @template {DeltaConf} Conf
|
|
2104
2051
|
* @overload
|
|
2105
2052
|
* @param {NodeName} nodeName
|
|
2106
|
-
* @param {Schema} schema
|
|
2107
|
-
* @return {
|
|
2053
|
+
* @param {s.Schema<Delta<Conf>>} schema
|
|
2054
|
+
* @return {DeltaBuilder<Conf, true>}
|
|
2108
2055
|
*/
|
|
2109
2056
|
/**
|
|
2110
2057
|
* @template {s.Schema<DeltaAny>} Schema
|
|
2111
2058
|
* @overload
|
|
2112
2059
|
* @param {Schema} schema
|
|
2113
|
-
* @return {Schema extends s.Schema<Delta<infer
|
|
2060
|
+
* @return {Schema extends s.Schema<Delta<infer Conf>> ? DeltaBuilder<Conf, true> : never}
|
|
2114
2061
|
*/
|
|
2115
2062
|
/**
|
|
2116
2063
|
* @template {string|null} NodeName
|
|
@@ -2149,7 +2096,7 @@ export const create = (nodeNameOrSchema, attrsOrSchema, children) => {
|
|
|
2149
2096
|
* @template {Array<any>|string} [Children=never]
|
|
2150
2097
|
* @overload
|
|
2151
2098
|
* @param {NodeName} nodeName
|
|
2152
|
-
* @param {...Array<Children>}
|
|
2099
|
+
* @param {...Array<Children>} children
|
|
2153
2100
|
* @return {DeltaBuilder<{
|
|
2154
2101
|
* name: NodeName,
|
|
2155
2102
|
* children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
|
|
@@ -2159,7 +2106,7 @@ export const create = (nodeNameOrSchema, attrsOrSchema, children) => {
|
|
|
2159
2106
|
/**
|
|
2160
2107
|
* @template {Array<any>|string} [Children=never]
|
|
2161
2108
|
* @overload
|
|
2162
|
-
* @param {...Array<Children>}
|
|
2109
|
+
* @param {...Array<Children>} children
|
|
2163
2110
|
* @return {DeltaBuilder<{
|
|
2164
2111
|
* children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
|
|
2165
2112
|
* text: Extract<Children,string> extends never ? false : true
|
|
@@ -2170,7 +2117,7 @@ export const create = (nodeNameOrSchema, attrsOrSchema, children) => {
|
|
|
2170
2117
|
* @template {Array<any>|string} [Children=never]
|
|
2171
2118
|
* @overload
|
|
2172
2119
|
* @param {Attrs} attrs
|
|
2173
|
-
* @param {...Array<Children>}
|
|
2120
|
+
* @param {...Array<Children>} children
|
|
2174
2121
|
* @return {DeltaBuilder<{
|
|
2175
2122
|
* attrs: Attrs extends null ? {} : Attrs,
|
|
2176
2123
|
* children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
|
|
@@ -2184,7 +2131,7 @@ export const create = (nodeNameOrSchema, attrsOrSchema, children) => {
|
|
|
2184
2131
|
* @overload
|
|
2185
2132
|
* @param {NodeName} nodeName
|
|
2186
2133
|
* @param {Attrs} attrs
|
|
2187
|
-
* @param {...Array<Children>}
|
|
2134
|
+
* @param {...Array<Children>} children
|
|
2188
2135
|
* @return {DeltaBuilder<{
|
|
2189
2136
|
* name: NodeName,
|
|
2190
2137
|
* attrs: Attrs extends null ? {} : Attrs,
|
|
@@ -2210,10 +2157,10 @@ export const from = (...args) => {
|
|
|
2210
2157
|
}
|
|
2211
2158
|
|
|
2212
2159
|
/**
|
|
2213
|
-
* @template {DeltaConf}
|
|
2214
|
-
* @param {Delta<
|
|
2215
|
-
* @param {NoInfer<Delta<
|
|
2216
|
-
* @return {DeltaBuilder<
|
|
2160
|
+
* @template {DeltaConf} Conf
|
|
2161
|
+
* @param {Delta<Conf>} d1
|
|
2162
|
+
* @param {NoInfer<Delta<Conf>>} d2
|
|
2163
|
+
* @return {DeltaBuilder<Conf>}
|
|
2217
2164
|
*/
|
|
2218
2165
|
export const diff = (d1, d2) => {
|
|
2219
2166
|
/**
|
package/src/environment.js
CHANGED
|
@@ -84,14 +84,13 @@ export const hasParam = (name) => computeParams().has(name)
|
|
|
84
84
|
*/
|
|
85
85
|
/* c8 ignore next 2 */
|
|
86
86
|
/* @__NO_SIDE_EFFECTS__ */
|
|
87
|
-
export const getParam = (name, defaultVal) =>
|
|
88
|
-
computeParams().get(name) || defaultVal
|
|
87
|
+
export const getParam = (name, defaultVal) => computeParams().get(name) || defaultVal
|
|
89
88
|
|
|
90
89
|
/**
|
|
91
90
|
* @param {string} name
|
|
92
91
|
* @return {string|null}
|
|
93
92
|
*/
|
|
94
|
-
/* c8 ignore next
|
|
93
|
+
/* c8 ignore next 5 */
|
|
95
94
|
/* @__NO_SIDE_EFFECTS__ */
|
|
96
95
|
export const getVariable = (name) =>
|
|
97
96
|
isNode
|