@minca/core 0.1.15 → 0.1.17
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 +10 -10
- package/dist/elements/auth-styles.d.ts +1 -1
- package/dist/elements/auth-styles.d.ts.map +1 -1
- package/dist/elements/auth-styles.js +35 -9
- package/dist/elements/auth-styles.js.map +1 -1
- package/dist/elements/minca-auth.d.ts.map +1 -1
- package/dist/elements/minca-auth.js +169 -72
- package/dist/elements/minca-auth.js.map +1 -1
- package/dist/identity/abilities.d.ts +2 -0
- package/dist/identity/abilities.d.ts.map +1 -1
- package/dist/identity/abilities.js +2 -0
- package/dist/identity/abilities.js.map +1 -1
- package/dist/identity/account-vault.d.ts +15 -71
- package/dist/identity/account-vault.d.ts.map +1 -1
- package/dist/identity/account-vault.js +45 -104
- package/dist/identity/account-vault.js.map +1 -1
- package/dist/identity/channel.d.ts +3 -9
- package/dist/identity/channel.d.ts.map +1 -1
- package/dist/identity/channel.js +42 -42
- package/dist/identity/channel.js.map +1 -1
- package/dist/identity/contact-key.d.ts +14 -29
- package/dist/identity/contact-key.d.ts.map +1 -1
- package/dist/identity/contact-key.js +31 -51
- package/dist/identity/contact-key.js.map +1 -1
- package/dist/identity/crypto-p256.d.ts.map +1 -1
- package/dist/identity/crypto-p256.js +39 -53
- package/dist/identity/crypto-p256.js.map +1 -1
- package/dist/identity/hpke.d.ts.map +1 -1
- package/dist/identity/hpke.js +19 -19
- package/dist/identity/hpke.js.map +1 -1
- package/dist/identity/identity-manager.d.ts.map +1 -1
- package/dist/identity/identity-manager.js +1 -2
- package/dist/identity/identity-manager.js.map +1 -1
- package/dist/identity/policy.d.ts.map +1 -1
- package/dist/identity/policy.js +35 -61
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/recovery-code.d.ts +2 -8
- package/dist/identity/recovery-code.d.ts.map +1 -1
- package/dist/identity/recovery-code.js +4 -11
- package/dist/identity/recovery-code.js.map +1 -1
- package/dist/identity/root-signer.d.ts +1 -6
- package/dist/identity/root-signer.d.ts.map +1 -1
- package/dist/identity/root-signer.js +12 -15
- package/dist/identity/root-signer.js.map +1 -1
- package/dist/identity/ucan.d.ts.map +1 -1
- package/dist/identity/ucan.js +48 -39
- package/dist/identity/ucan.js.map +1 -1
- package/dist/identity/webauthn.d.ts +6 -11
- package/dist/identity/webauthn.d.ts.map +1 -1
- package/dist/identity/webauthn.js +18 -30
- package/dist/identity/webauthn.js.map +1 -1
- package/dist/inbox/inbox.d.ts.map +1 -1
- package/dist/inbox/inbox.js +40 -30
- package/dist/inbox/inbox.js.map +1 -1
- package/dist/inbox/index.d.ts +2 -0
- package/dist/inbox/index.d.ts.map +1 -1
- package/dist/inbox/index.js +1 -0
- package/dist/inbox/index.js.map +1 -1
- package/dist/inbox/names.d.ts +54 -0
- package/dist/inbox/names.d.ts.map +1 -0
- package/dist/inbox/names.js +299 -0
- package/dist/inbox/names.js.map +1 -0
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -12
- package/dist/index.js.map +1 -1
- package/dist/network/mesh.d.ts +7 -20
- package/dist/network/mesh.d.ts.map +1 -1
- package/dist/network/mesh.js +267 -245
- package/dist/network/mesh.js.map +1 -1
- package/dist/network/relay-link.d.ts +31 -0
- package/dist/network/relay-link.d.ts.map +1 -0
- package/dist/network/relay-link.js +62 -0
- package/dist/network/relay-link.js.map +1 -0
- package/dist/network/relay-minca.d.ts.map +1 -1
- package/dist/network/relay-minca.js +11 -49
- package/dist/network/relay-minca.js.map +1 -1
- package/dist/network/relay-nostr.d.ts.map +1 -1
- package/dist/network/relay-nostr.js +23 -63
- package/dist/network/relay-nostr.js.map +1 -1
- package/dist/network/relay-socket.d.ts +1 -1
- package/dist/network/relay-socket.d.ts.map +1 -1
- package/dist/network/relay-socket.js +3 -1
- package/dist/network/relay-socket.js.map +1 -1
- package/dist/network/ws-transport.d.ts.map +1 -1
- package/dist/network/ws-transport.js +3 -0
- package/dist/network/ws-transport.js.map +1 -1
- package/dist/node/actions.d.ts +2 -0
- package/dist/node/actions.d.ts.map +1 -1
- package/dist/node/actions.js +89 -58
- package/dist/node/actions.js.map +1 -1
- package/dist/node/api.d.ts +7 -0
- package/dist/node/api.d.ts.map +1 -1
- package/dist/node/api.js +7 -0
- package/dist/node/api.js.map +1 -1
- package/dist/node/carrier.d.ts +5 -0
- package/dist/node/carrier.d.ts.map +1 -1
- package/dist/node/carrier.js +94 -73
- package/dist/node/carrier.js.map +1 -1
- package/dist/node/copy.d.ts +8 -7
- package/dist/node/copy.d.ts.map +1 -1
- package/dist/node/copy.js +54 -56
- package/dist/node/copy.js.map +1 -1
- package/dist/node/host.d.ts +39 -65
- package/dist/node/host.d.ts.map +1 -1
- package/dist/node/host.js +362 -379
- package/dist/node/host.js.map +1 -1
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/node-carriers.d.ts +35 -0
- package/dist/node/node-carriers.d.ts.map +1 -0
- package/dist/node/node-carriers.js +567 -0
- package/dist/node/node-carriers.js.map +1 -0
- package/dist/node/node-contacts.d.ts +11 -0
- package/dist/node/node-contacts.d.ts.map +1 -0
- package/dist/node/node-contacts.js +808 -0
- package/dist/node/node-contacts.js.map +1 -0
- package/dist/node/node-context.d.ts +76 -0
- package/dist/node/node-context.d.ts.map +1 -0
- package/dist/node/node-context.js +54 -0
- package/dist/node/node-context.js.map +1 -0
- package/dist/node/node-hosting.d.ts +20 -0
- package/dist/node/node-hosting.d.ts.map +1 -0
- package/dist/node/node-hosting.js +456 -0
- package/dist/node/node-hosting.js.map +1 -0
- package/dist/node/node-records.d.ts +18 -0
- package/dist/node/node-records.d.ts.map +1 -0
- package/dist/node/node-records.js +262 -0
- package/dist/node/node-records.js.map +1 -0
- package/dist/node/node.d.ts.map +1 -1
- package/dist/node/node.js +199 -1990
- package/dist/node/node.js.map +1 -1
- package/dist/node/remote.d.ts +5 -6
- package/dist/node/remote.d.ts.map +1 -1
- package/dist/node/remote.js +272 -260
- package/dist/node/remote.js.map +1 -1
- package/dist/node/space-catalog.d.ts +40 -0
- package/dist/node/space-catalog.d.ts.map +1 -0
- package/dist/node/space-catalog.js +158 -0
- package/dist/node/space-catalog.js.map +1 -0
- package/dist/node/space-checks.d.ts +25 -0
- package/dist/node/space-checks.d.ts.map +1 -0
- package/dist/node/space-checks.js +343 -0
- package/dist/node/space-checks.js.map +1 -0
- package/dist/node/space-history.d.ts +37 -0
- package/dist/node/space-history.d.ts.map +1 -0
- package/dist/node/space-history.js +350 -0
- package/dist/node/space-history.js.map +1 -0
- package/dist/node/space-holding.d.ts +53 -0
- package/dist/node/space-holding.d.ts.map +1 -0
- package/dist/node/space-holding.js +339 -0
- package/dist/node/space-holding.js.map +1 -0
- package/dist/node/space-index.d.ts +41 -0
- package/dist/node/space-index.d.ts.map +1 -0
- package/dist/node/space-index.js +217 -0
- package/dist/node/space-index.js.map +1 -0
- package/dist/node/space-keys.d.ts +34 -0
- package/dist/node/space-keys.d.ts.map +1 -0
- package/dist/node/space-keys.js +309 -0
- package/dist/node/space-keys.js.map +1 -0
- package/dist/node/space-lines.d.ts +33 -0
- package/dist/node/space-lines.d.ts.map +1 -0
- package/dist/node/space-lines.js +145 -0
- package/dist/node/space-lines.js.map +1 -0
- package/dist/node/space-membership.d.ts +69 -0
- package/dist/node/space-membership.d.ts.map +1 -0
- package/dist/node/space-membership.js +242 -0
- package/dist/node/space-membership.js.map +1 -0
- package/dist/node/space-mirrors.d.ts +43 -0
- package/dist/node/space-mirrors.d.ts.map +1 -0
- package/dist/node/space-mirrors.js +125 -0
- package/dist/node/space-mirrors.js.map +1 -0
- package/dist/node/space-peers.d.ts +104 -0
- package/dist/node/space-peers.d.ts.map +1 -0
- package/dist/node/space-peers.js +629 -0
- package/dist/node/space-peers.js.map +1 -0
- package/dist/node/space-profiles.d.ts +18 -0
- package/dist/node/space-profiles.d.ts.map +1 -0
- package/dist/node/space-profiles.js +105 -0
- package/dist/node/space-profiles.js.map +1 -0
- package/dist/node/space-rules.d.ts +29 -0
- package/dist/node/space-rules.d.ts.map +1 -0
- package/dist/node/space-rules.js +144 -0
- package/dist/node/space-rules.js.map +1 -0
- package/dist/node/space-runtime.d.ts +107 -140
- package/dist/node/space-runtime.d.ts.map +1 -1
- package/dist/node/space-runtime.js +331 -3985
- package/dist/node/space-runtime.js.map +1 -1
- package/dist/node/space-standing.d.ts +20 -0
- package/dist/node/space-standing.d.ts.map +1 -0
- package/dist/node/space-standing.js +317 -0
- package/dist/node/space-standing.js.map +1 -0
- package/dist/node/space-versions.d.ts +104 -0
- package/dist/node/space-versions.d.ts.map +1 -0
- package/dist/node/space-versions.js +153 -0
- package/dist/node/space-versions.js.map +1 -0
- package/dist/node/space-warrants.d.ts +25 -0
- package/dist/node/space-warrants.d.ts.map +1 -0
- package/dist/node/space-warrants.js +214 -0
- package/dist/node/space-warrants.js.map +1 -0
- package/dist/node/space-writing.d.ts +74 -0
- package/dist/node/space-writing.d.ts.map +1 -0
- package/dist/node/space-writing.js +442 -0
- package/dist/node/space-writing.js.map +1 -0
- package/dist/node/stores.d.ts +19 -50
- package/dist/node/stores.d.ts.map +1 -1
- package/dist/node/stores.js +14 -33
- package/dist/node/stores.js.map +1 -1
- package/dist/node/types.d.ts +243 -306
- package/dist/node/types.d.ts.map +1 -1
- package/dist/node/usage.d.ts +2 -24
- package/dist/node/usage.d.ts.map +1 -1
- package/dist/node/usage.js +118 -102
- package/dist/node/usage.js.map +1 -1
- package/dist/node/watch-notifications.d.ts.map +1 -1
- package/dist/node/watch-notifications.js +32 -29
- package/dist/node/watch-notifications.js.map +1 -1
- package/dist/node/worker.d.ts +5 -6
- package/dist/node/worker.d.ts.map +1 -1
- package/dist/node/worker.js +80 -72
- package/dist/node/worker.js.map +1 -1
- package/dist/node/writer-keys.d.ts +5 -6
- package/dist/node/writer-keys.d.ts.map +1 -1
- package/dist/node/writer-keys.js +66 -57
- package/dist/node/writer-keys.js.map +1 -1
- package/dist/node/writers.d.ts +12 -19
- package/dist/node/writers.d.ts.map +1 -1
- package/dist/node/writers.js +7 -15
- package/dist/node/writers.js.map +1 -1
- package/dist/privacy/direct.d.ts.map +1 -1
- package/dist/privacy/direct.js +31 -27
- package/dist/privacy/direct.js.map +1 -1
- package/dist/privacy/space-encryption.d.ts.map +1 -1
- package/dist/privacy/space-encryption.js +5 -9
- package/dist/privacy/space-encryption.js.map +1 -1
- package/dist/query/computed.d.ts.map +1 -1
- package/dist/query/computed.js +78 -77
- package/dist/query/computed.js.map +1 -1
- package/dist/query/engine.d.ts +3 -4
- package/dist/query/engine.d.ts.map +1 -1
- package/dist/query/engine.js +93 -86
- package/dist/query/engine.js.map +1 -1
- package/dist/query/filter.d.ts +8 -10
- package/dist/query/filter.d.ts.map +1 -1
- package/dist/query/filter.js +144 -161
- package/dist/query/filter.js.map +1 -1
- package/dist/records/cel-types.d.ts.map +1 -1
- package/dist/records/cel-types.js +13 -27
- package/dist/records/cel-types.js.map +1 -1
- package/dist/records/cel.d.ts.map +1 -1
- package/dist/records/cel.js +177 -242
- package/dist/records/cel.js.map +1 -1
- package/dist/records/rules.d.ts.map +1 -1
- package/dist/records/rules.js +46 -50
- package/dist/records/rules.js.map +1 -1
- package/dist/records/topics.d.ts.map +1 -1
- package/dist/records/topics.js +18 -22
- package/dist/records/topics.js.map +1 -1
- package/dist/schemas/automations.d.ts +8 -15
- package/dist/schemas/automations.d.ts.map +1 -1
- package/dist/schemas/automations.js +203 -165
- package/dist/schemas/automations.js.map +1 -1
- package/dist/schemas/blueprints.d.ts.map +1 -1
- package/dist/schemas/blueprints.js +14 -13
- package/dist/schemas/blueprints.js.map +1 -1
- package/dist/schemas/connectors.d.ts.map +1 -1
- package/dist/schemas/connectors.js +16 -11
- package/dist/schemas/connectors.js.map +1 -1
- package/dist/schemas/contacts.d.ts +57 -0
- package/dist/schemas/contacts.d.ts.map +1 -1
- package/dist/schemas/contacts.js +32 -0
- package/dist/schemas/contacts.js.map +1 -1
- package/dist/schemas/cron.d.ts.map +1 -1
- package/dist/schemas/cron.js +27 -28
- package/dist/schemas/cron.js.map +1 -1
- package/dist/schemas/defined.d.ts +6 -0
- package/dist/schemas/defined.d.ts.map +1 -0
- package/dist/schemas/defined.js +7 -0
- package/dist/schemas/defined.js.map +1 -0
- package/dist/schemas/guides.d.ts +3 -1
- package/dist/schemas/guides.d.ts.map +1 -1
- package/dist/schemas/guides.js +13 -12
- package/dist/schemas/guides.js.map +1 -1
- package/dist/schemas/index.d.ts +2 -2
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +18 -14
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/library/social.d.ts +258 -0
- package/dist/schemas/library/social.d.ts.map +1 -1
- package/dist/schemas/library/social.js +28 -1
- package/dist/schemas/library/social.js.map +1 -1
- package/dist/session/account-hint.d.ts.map +1 -1
- package/dist/session/account-hint.js +8 -5
- package/dist/session/account-hint.js.map +1 -1
- package/dist/session/auth.d.ts +36 -2
- package/dist/session/auth.d.ts.map +1 -1
- package/dist/session/auth.js +95 -2
- package/dist/session/auth.js.map +1 -1
- package/dist/session/connect.d.ts +1 -0
- package/dist/session/connect.d.ts.map +1 -1
- package/dist/session/connect.js +3 -1
- package/dist/session/connect.js.map +1 -1
- package/dist/session/credentials.d.ts +8 -26
- package/dist/session/credentials.d.ts.map +1 -1
- package/dist/session/credentials.js +14 -32
- package/dist/session/credentials.js.map +1 -1
- package/dist/session/hosting.d.ts.map +1 -1
- package/dist/session/hosting.js +8 -2
- package/dist/session/hosting.js.map +1 -1
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +1 -0
- package/dist/session/index.js.map +1 -1
- package/dist/session/pairing.d.ts.map +1 -1
- package/dist/session/pairing.js +92 -88
- package/dist/session/pairing.js.map +1 -1
- package/dist/session/password-strength.d.ts.map +1 -1
- package/dist/session/password-strength.js +37 -37
- package/dist/session/password-strength.js.map +1 -1
- package/dist/session/places.d.ts.map +1 -1
- package/dist/session/places.js +18 -13
- package/dist/session/places.js.map +1 -1
- package/dist/session/popup.d.ts +13 -0
- package/dist/session/popup.d.ts.map +1 -0
- package/dist/session/popup.js +23 -0
- package/dist/session/popup.js.map +1 -0
- package/dist/space/constitution.d.ts.map +1 -1
- package/dist/space/constitution.js +22 -29
- package/dist/space/constitution.js.map +1 -1
- package/dist/space/grants.d.ts.map +1 -1
- package/dist/space/grants.js +37 -39
- package/dist/space/grants.js.map +1 -1
- package/dist/space/invite-link.d.ts.map +1 -1
- package/dist/space/invite-link.js +33 -33
- package/dist/space/invite-link.js.map +1 -1
- package/dist/space/own-automations.d.ts +13 -24
- package/dist/space/own-automations.d.ts.map +1 -1
- package/dist/space/own-automations.js +47 -37
- package/dist/space/own-automations.js.map +1 -1
- package/dist/space/presets.d.ts +2 -2
- package/dist/space/presets.d.ts.map +1 -1
- package/dist/space/presets.js +3 -2
- package/dist/space/presets.js.map +1 -1
- package/dist/space/roles.d.ts +56 -80
- package/dist/space/roles.d.ts.map +1 -1
- package/dist/space/roles.js +448 -441
- package/dist/space/roles.js.map +1 -1
- package/dist/space/space-access.d.ts +3 -4
- package/dist/space/space-access.d.ts.map +1 -1
- package/dist/space/space-access.js +3 -8
- package/dist/space/space-access.js.map +1 -1
- package/dist/storage/blob/directory.d.ts.map +1 -1
- package/dist/storage/blob/directory.js +39 -32
- package/dist/storage/blob/directory.js.map +1 -1
- package/dist/storage/blob/s3.d.ts.map +1 -1
- package/dist/storage/blob/s3.js +21 -19
- package/dist/storage/blob/s3.js.map +1 -1
- package/dist/storage/blob-store.d.ts +0 -9
- package/dist/storage/blob-store.d.ts.map +1 -1
- package/dist/storage/directory-access.d.ts +8 -32
- package/dist/storage/directory-access.d.ts.map +1 -1
- package/dist/storage/directory-access.js +11 -36
- package/dist/storage/directory-access.js.map +1 -1
- package/dist/storage/encrypted-adapter.d.ts +12 -32
- package/dist/storage/encrypted-adapter.d.ts.map +1 -1
- package/dist/storage/encrypted-adapter.js +31 -54
- package/dist/storage/encrypted-adapter.js.map +1 -1
- package/dist/storage/folder-adapter.d.ts +12 -26
- package/dist/storage/folder-adapter.d.ts.map +1 -1
- package/dist/storage/folder-adapter.js +37 -54
- package/dist/storage/folder-adapter.js.map +1 -1
- package/dist/storage/folder-reconcile.d.ts +12 -26
- package/dist/storage/folder-reconcile.d.ts.map +1 -1
- package/dist/storage/folder-reconcile.js +39 -48
- package/dist/storage/folder-reconcile.js.map +1 -1
- package/dist/storage/indexeddb-adapter.d.ts +2 -6
- package/dist/storage/indexeddb-adapter.d.ts.map +1 -1
- package/dist/storage/indexeddb-adapter.js +60 -114
- package/dist/storage/indexeddb-adapter.js.map +1 -1
- package/dist/storage/mirror.d.ts +0 -29
- package/dist/storage/mirror.d.ts.map +1 -1
- package/dist/storage/mirror.js +153 -110
- package/dist/storage/mirror.js.map +1 -1
- package/dist/storage/segment.d.ts.map +1 -1
- package/dist/storage/segment.js +3 -7
- package/dist/storage/segment.js.map +1 -1
- package/dist/storage/storage-provider.d.ts +6 -11
- package/dist/storage/storage-provider.d.ts.map +1 -1
- package/dist/storage/storage-provider.js +112 -116
- package/dist/storage/storage-provider.js.map +1 -1
- package/dist/sync/sync-engine.d.ts +10 -44
- package/dist/sync/sync-engine.d.ts.map +1 -1
- package/dist/sync/sync-engine.js +245 -247
- package/dist/sync/sync-engine.js.map +1 -1
- package/dist/sync/sync-messages.d.ts +1 -1
- package/dist/sync/sync-messages.d.ts.map +1 -1
- package/dist/sync/sync-messages.js +1 -1
- package/dist/sync/sync-messages.js.map +1 -1
- package/dist/utils/guards.d.ts +1 -0
- package/dist/utils/guards.d.ts.map +1 -1
- package/dist/utils/guards.js +1 -0
- package/dist/utils/guards.js.map +1 -1
- package/dist/utils/hmac.d.ts +5 -0
- package/dist/utils/hmac.d.ts.map +1 -0
- package/dist/utils/hmac.js +20 -0
- package/dist/utils/hmac.js.map +1 -0
- package/dist/utils/map.d.ts +10 -0
- package/dist/utils/map.d.ts.map +1 -0
- package/dist/utils/map.js +30 -0
- package/dist/utils/map.js.map +1 -0
- package/dist/utils/serial.d.ts +2 -0
- package/dist/utils/serial.d.ts.map +1 -1
- package/dist/utils/serial.js +9 -0
- package/dist/utils/serial.js.map +1 -1
- package/dist/validation/capability-gate.d.ts +7 -15
- package/dist/validation/capability-gate.d.ts.map +1 -1
- package/dist/validation/capability-gate.js +32 -36
- package/dist/validation/capability-gate.js.map +1 -1
- package/dist/validation/crypto-gate.d.ts.map +1 -1
- package/dist/validation/crypto-gate.js +12 -21
- package/dist/validation/crypto-gate.js.map +1 -1
- package/docs/README.md +1 -0
- package/docs/actions.md +32 -25
- package/docs/agents.md +28 -16
- package/docs/automations.md +1 -1
- package/docs/blueprints-and-guides.md +37 -5
- package/docs/building-an-app.md +7 -4
- package/docs/collections.md +3 -3
- package/docs/contacts.md +34 -1
- package/docs/contracts.md +1 -1
- package/docs/direct-messages.md +6 -2
- package/docs/inbox.md +5 -11
- package/docs/node.md +54 -22
- package/docs/records-and-queries.md +1 -1
- package/docs/sign-in.md +54 -26
- package/docs/spaces.md +9 -8
- package/docs/standard-library.md +37 -14
- package/docs/storage.md +5 -6
- package/docs/usernames.md +161 -0
- package/docs/warrants.md +1 -1
- package/package.json +1 -2
|
@@ -14,31 +14,25 @@
|
|
|
14
14
|
* versions/<cid>.json
|
|
15
15
|
* ```
|
|
16
16
|
*
|
|
17
|
-
* **Versions are the truth; the entries are an index over them.**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* mutable thing, which version is current, is derived state that either side
|
|
22
|
-
* can put right. {@link reconcileFolder} is what puts it right.
|
|
17
|
+
* **Versions are the truth; the entries are an index over them.** Version
|
|
18
|
+
* files are immutable and named by their content hash, so two origins can
|
|
19
|
+
* share a folder without locking; which version is current is derived, and
|
|
20
|
+
* {@link reconcileFolder} puts it right.
|
|
23
21
|
*/
|
|
24
22
|
import { utf8Encode, utf8Decode } from '../utils/encoding.js';
|
|
25
23
|
import { isStoredVersion } from '../utils/guards.js';
|
|
26
24
|
const VERSION_SUFFIX = '.json';
|
|
25
|
+
const versionFile = (id) => encodeKey(id) + VERSION_SUFFIX;
|
|
27
26
|
/**
|
|
28
|
-
* Percent-encodes a storage key into a filename.
|
|
29
|
-
*
|
|
30
|
-
* Only lowercase is left unescaped, which looks excessive until you remember
|
|
31
|
-
* that macOS and Windows filesystems are case-insensitive by default: without
|
|
32
|
-
* this, the keys `space:Abc` and `space:abc` would quietly become one file and
|
|
33
|
-
* one of the two values would be lost.
|
|
27
|
+
* Percent-encodes a storage key into a filename. Upper case is escaped too:
|
|
28
|
+
* on a case-insensitive filesystem `space:Abc` and `space:abc` would be one file.
|
|
34
29
|
*/
|
|
35
30
|
export function encodeKey(key) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
return out;
|
|
31
|
+
return Array.from(utf8Encode(key), encodeByte).join('');
|
|
32
|
+
}
|
|
33
|
+
function encodeByte(byte) {
|
|
34
|
+
const char = String.fromCharCode(byte);
|
|
35
|
+
return /[a-z0-9._-]/.test(char) ? char : `%${byte.toString(16).padStart(2, '0').toUpperCase()}`;
|
|
42
36
|
}
|
|
43
37
|
/** Reverses {@link encodeKey}. */
|
|
44
38
|
export function decodeKey(name) {
|
|
@@ -97,28 +91,21 @@ export async function removeFile(dir, name) {
|
|
|
97
91
|
}
|
|
98
92
|
}
|
|
99
93
|
/**
|
|
100
|
-
* Opens a storage adapter backed by a directory on the user's disk.
|
|
94
|
+
* Opens a storage adapter backed by a directory on the user's disk. Versions
|
|
95
|
+
* are held in memory too, or a query would read one file per record.
|
|
101
96
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* The cost is that the working set has to fit in memory.
|
|
105
|
-
*
|
|
106
|
-
* @param path Where to keep these files inside it, `/` separating
|
|
107
|
-
* subdirectories. The full path from the folder root, so that several
|
|
108
|
-
* accounts can each have a subtree of their own.
|
|
97
|
+
* @param path Where to keep these files from the folder root, `/` separating
|
|
98
|
+
* subdirectories, so several accounts can each have a subtree.
|
|
109
99
|
*/
|
|
110
100
|
export async function createFolderAdapter(root, path) {
|
|
111
101
|
const segments = path.split('/').filter(Boolean).map(encodeKey);
|
|
112
|
-
if (segments.length === 0)
|
|
102
|
+
if (segments.length === 0)
|
|
113
103
|
throw new Error('A folder adapter needs a path to live in.');
|
|
114
|
-
}
|
|
115
104
|
const base = await resolvePath(root, segments);
|
|
116
105
|
const kvDir = await base.getDirectoryHandle('kv', { create: true });
|
|
117
106
|
const versionsDir = await base.getDirectoryHandle('versions', { create: true });
|
|
118
107
|
const versions = new Map();
|
|
119
|
-
|
|
120
|
-
// pointer does change, which is why `reload` throws the whole cache away
|
|
121
|
-
// rather than trying to be clever about which entries are still good.
|
|
108
|
+
/** Entries read or written, null for a miss; `reload` drops it, since another writer may have changed any */
|
|
122
109
|
const kvCache = new Map();
|
|
123
110
|
async function readVersionFile(name) {
|
|
124
111
|
const bytes = await readFolderFile(versionsDir, name);
|
|
@@ -129,11 +116,18 @@ export async function createFolderAdapter(root, path) {
|
|
|
129
116
|
return isStoredVersion(parsed) ? parsed : null;
|
|
130
117
|
}
|
|
131
118
|
catch {
|
|
132
|
-
//
|
|
133
|
-
// rewritten or stay unreadable; either way it is not ours to repair.
|
|
119
|
+
// Half written by a writer that died mid-flush: not ours to repair.
|
|
134
120
|
return null;
|
|
135
121
|
}
|
|
136
122
|
}
|
|
123
|
+
async function put(key, value) {
|
|
124
|
+
await writeFolderFile(kvDir, encodeKey(key), value);
|
|
125
|
+
kvCache.set(key, value);
|
|
126
|
+
}
|
|
127
|
+
async function remove(key) {
|
|
128
|
+
await removeFile(kvDir, encodeKey(key));
|
|
129
|
+
kvCache.set(key, null);
|
|
130
|
+
}
|
|
137
131
|
async function reload() {
|
|
138
132
|
const seen = new Set();
|
|
139
133
|
const added = [];
|
|
@@ -171,14 +165,8 @@ export async function createFolderAdapter(root, path) {
|
|
|
171
165
|
kvCache.set(key, bytes);
|
|
172
166
|
return bytes;
|
|
173
167
|
},
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
kvCache.set(key, value);
|
|
177
|
-
},
|
|
178
|
-
async delete(key) {
|
|
179
|
-
await removeFile(kvDir, encodeKey(key));
|
|
180
|
-
kvCache.set(key, null);
|
|
181
|
-
},
|
|
168
|
+
put,
|
|
169
|
+
delete: remove,
|
|
182
170
|
async list(prefix = '') {
|
|
183
171
|
const keys = [];
|
|
184
172
|
for await (const name of kvDir.keys()) {
|
|
@@ -186,15 +174,14 @@ export async function createFolderAdapter(root, path) {
|
|
|
186
174
|
if (!key.startsWith(prefix))
|
|
187
175
|
continue;
|
|
188
176
|
keys.push(key);
|
|
189
|
-
// Another writer created it
|
|
190
|
-
// nothing. The file is on disk now, so the remembered miss is stale.
|
|
177
|
+
// Another writer created it since this process missed it.
|
|
191
178
|
if (kvCache.get(key) === null)
|
|
192
179
|
kvCache.delete(key);
|
|
193
180
|
}
|
|
194
181
|
return keys;
|
|
195
182
|
},
|
|
196
183
|
async putVersion(version) {
|
|
197
|
-
await writeFolderFile(versionsDir,
|
|
184
|
+
await writeFolderFile(versionsDir, versionFile(version.id), utf8Encode(JSON.stringify(version)));
|
|
198
185
|
versions.set(version.id, version);
|
|
199
186
|
},
|
|
200
187
|
async getVersion(id) {
|
|
@@ -202,25 +189,21 @@ export async function createFolderAdapter(root, path) {
|
|
|
202
189
|
if (known)
|
|
203
190
|
return known;
|
|
204
191
|
// Not in memory: another origin may have written it since the last reload.
|
|
205
|
-
const version = await readVersionFile(
|
|
192
|
+
const version = await readVersionFile(versionFile(id));
|
|
206
193
|
if (version)
|
|
207
194
|
versions.set(id, version);
|
|
208
195
|
return version;
|
|
209
196
|
},
|
|
210
197
|
async deleteVersion(id) {
|
|
211
|
-
await removeFile(versionsDir,
|
|
198
|
+
await removeFile(versionsDir, versionFile(id));
|
|
212
199
|
versions.delete(id);
|
|
213
200
|
},
|
|
214
201
|
async batch(ops) {
|
|
215
202
|
for (const op of ops) {
|
|
216
|
-
if (op.type === 'put')
|
|
217
|
-
await
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
else {
|
|
221
|
-
await removeFile(kvDir, encodeKey(op.key));
|
|
222
|
-
kvCache.set(op.key, null);
|
|
223
|
-
}
|
|
203
|
+
if (op.type === 'put')
|
|
204
|
+
await put(op.key, op.value);
|
|
205
|
+
else
|
|
206
|
+
await remove(op.key);
|
|
224
207
|
}
|
|
225
208
|
},
|
|
226
209
|
async close() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"folder-adapter.js","sourceRoot":"","sources":["../../src/storage/folder-adapter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"folder-adapter.js","sourceRoot":"","sources":["../../src/storage/folder-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AA6CrD,MAAM,cAAc,GAAG,OAAO,CAAC;AAC/B,MAAM,WAAW,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC;AAEnE;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,QAAQ,C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
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* So the rule is: **the set of version files wins.** Reconciling means
|
|
12
|
-
* placing every file that turned up — which also puts right a current-version
|
|
13
|
-
* entry the other writer overwrote — and dropping entries whose file went
|
|
14
|
-
* away. That is the whole concurrency story.
|
|
4
|
+
* Two origins, or two devices behind a sync service, can write one folder at
|
|
5
|
+
* once. Version files are named by their content hash, so they never
|
|
6
|
+
* conflict; the entries saying which version is current can be lost to a
|
|
7
|
+
* race, but they are derived from the files. So **the set of version files
|
|
8
|
+
* wins**: reconciling places every file that turned up and drops entries
|
|
9
|
+
* whose file went away.
|
|
15
10
|
*/
|
|
16
11
|
import type { StorageProvider } from './storage-provider.js';
|
|
17
12
|
import type { FolderAdapter } from './folder-adapter.js';
|
|
@@ -22,26 +17,17 @@ export interface FolderReconciliation {
|
|
|
22
17
|
readonly added: ReadonlyArray<string>;
|
|
23
18
|
/** Version files that are gone */
|
|
24
19
|
readonly removed: ReadonlyArray<string>;
|
|
25
|
-
/**
|
|
26
|
-
* Versions placed or unplaced to match the directory: files another writer
|
|
27
|
-
* added (placed again, which corrects a current entry a race left wrong),
|
|
28
|
-
* files that came back from Dropbox with no entries, and entries whose file
|
|
29
|
-
* is gone.
|
|
30
|
-
*/
|
|
20
|
+
/** Versions placed or unplaced to match the directory */
|
|
31
21
|
readonly repaired: ReadonlyArray<string>;
|
|
32
22
|
/** Whether anything moved at all — worth a re-render when true */
|
|
33
23
|
readonly changed: boolean;
|
|
34
24
|
}
|
|
35
25
|
/**
|
|
36
|
-
* Re-reads the folder and brings the entries back in line with it.
|
|
37
|
-
*
|
|
38
|
-
* Safe to call as often as you like: with nothing new on disk it is two
|
|
39
|
-
* directory listings and no writes.
|
|
26
|
+
* Re-reads the folder and brings the entries back in line with it. With
|
|
27
|
+
* nothing new on disk it is two listings and no writes.
|
|
40
28
|
*
|
|
41
|
-
* @param accept Whether a version found on disk may be placed
|
|
42
|
-
* write the folder can drop a file in it
|
|
43
|
-
* sync service — so what turns up there is checked like anything arriving
|
|
44
|
-
* from a peer. A version refused now stays on disk and is asked about again.
|
|
29
|
+
* @param accept Whether a version found on disk may be placed: anyone who can
|
|
30
|
+
* write the folder can drop a file in it. One refused now is asked about again.
|
|
45
31
|
*/
|
|
46
32
|
export declare function reconcileFolder(storage: StorageProvider, adapter: FolderAdapter, accept?: (version: Version) => Promise<boolean>): Promise<FolderReconciliation>;
|
|
47
33
|
//# sourceMappingURL=folder-reconcile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"folder-reconcile.d.ts","sourceRoot":"","sources":["../../src/storage/folder-reconcile.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"folder-reconcile.d.ts","sourceRoot":"","sources":["../../src/storage/folder-reconcile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,wCAAwC;AACxC,MAAM,WAAW,oBAAoB;IACnC,gFAAgF;IAChF,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,kCAAkC;IAClC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACzC,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,aAAa,EACtB,MAAM,GAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAoB,GAChE,OAAO,CAAC,oBAAoB,CAAC,CAY/B"}
|
|
@@ -1,67 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Making a shared folder converge
|
|
2
|
+
* Making a shared folder converge without anybody taking a lock.
|
|
3
3
|
*
|
|
4
|
-
* Two origins
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* So the rule is: **the set of version files wins.** Reconciling means
|
|
12
|
-
* placing every file that turned up — which also puts right a current-version
|
|
13
|
-
* entry the other writer overwrote — and dropping entries whose file went
|
|
14
|
-
* away. That is the whole concurrency story.
|
|
4
|
+
* Two origins, or two devices behind a sync service, can write one folder at
|
|
5
|
+
* once. Version files are named by their content hash, so they never
|
|
6
|
+
* conflict; the entries saying which version is current can be lost to a
|
|
7
|
+
* race, but they are derived from the files. So **the set of version files
|
|
8
|
+
* wins**: reconciling places every file that turned up and drops entries
|
|
9
|
+
* whose file went away.
|
|
15
10
|
*/
|
|
16
11
|
/**
|
|
17
|
-
* Re-reads the folder and brings the entries back in line with it.
|
|
18
|
-
*
|
|
19
|
-
* Safe to call as often as you like: with nothing new on disk it is two
|
|
20
|
-
* directory listings and no writes.
|
|
12
|
+
* Re-reads the folder and brings the entries back in line with it. With
|
|
13
|
+
* nothing new on disk it is two listings and no writes.
|
|
21
14
|
*
|
|
22
|
-
* @param accept Whether a version found on disk may be placed
|
|
23
|
-
* write the folder can drop a file in it
|
|
24
|
-
* sync service — so what turns up there is checked like anything arriving
|
|
25
|
-
* from a peer. A version refused now stays on disk and is asked about again.
|
|
15
|
+
* @param accept Whether a version found on disk may be placed: anyone who can
|
|
16
|
+
* write the folder can drop a file in it. One refused now is asked about again.
|
|
26
17
|
*/
|
|
27
18
|
export async function reconcileFolder(storage, adapter, accept = async () => true) {
|
|
28
19
|
const disk = await adapter.reload();
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
const moved = disk.added.length > 0 || disk.removed.length > 0;
|
|
21
|
+
// Sync compares entries, and another writer's are on disk now too.
|
|
22
|
+
if (moved)
|
|
31
23
|
storage.invalidate();
|
|
32
24
|
const onDisk = new Set(await adapter.listVersionIds());
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
const placed = await placeNew(storage, adapter, onDisk, new Set(disk.added), accept);
|
|
26
|
+
const dropped = await dropGone(storage, adapter, onDisk);
|
|
27
|
+
const repaired = [...placed, ...dropped];
|
|
28
|
+
return { added: disk.added, removed: disk.removed, repaired, changed: moved || repaired.length > 0 };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Places files not indexed yet, and those that just appeared even if they
|
|
32
|
+
* are: placing is idempotent and corrects a current entry a race left wrong.
|
|
33
|
+
*/
|
|
34
|
+
async function placeNew(storage, adapter, onDisk, appeared, accept) {
|
|
38
35
|
const indexed = new Set(await storage.versionIds());
|
|
39
|
-
const appeared = new Set(disk.added);
|
|
40
|
-
const missing = [...onDisk].filter((id) => !indexed.has(id) || appeared.has(id));
|
|
41
36
|
const placed = [];
|
|
42
|
-
for (const id of
|
|
37
|
+
for (const id of onDisk) {
|
|
38
|
+
if (indexed.has(id) && !appeared.has(id))
|
|
39
|
+
continue;
|
|
40
|
+
// A file can vanish between listing and reading; the next pass agrees.
|
|
43
41
|
const version = await adapter.getVersion(id);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
placed.push(id);
|
|
49
|
-
}
|
|
42
|
+
if (!version || !(await accept(version)))
|
|
43
|
+
continue;
|
|
44
|
+
await storage.addVersion(version);
|
|
45
|
+
placed.push(id);
|
|
50
46
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
return placed;
|
|
48
|
+
}
|
|
49
|
+
/** Drops entries whose file another writer superseded and deleted */
|
|
50
|
+
async function dropGone(storage, adapter, onDisk) {
|
|
51
|
+
const gone = (await storage.versionIds()).filter((id) => !onDisk.has(id));
|
|
52
|
+
for (const id of gone) {
|
|
55
53
|
if (!(await adapter.getVersion(id)))
|
|
56
54
|
await storage.removeVersion(id);
|
|
57
55
|
}
|
|
58
|
-
|
|
59
|
-
const repaired = [...placed, ...stale];
|
|
60
|
-
return {
|
|
61
|
-
added: disk.added,
|
|
62
|
-
removed: disk.removed,
|
|
63
|
-
repaired,
|
|
64
|
-
changed: disk.added.length > 0 || disk.removed.length > 0 || repaired.length > 0,
|
|
65
|
-
};
|
|
56
|
+
return gone;
|
|
66
57
|
}
|
|
67
58
|
//# sourceMappingURL=folder-reconcile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"folder-reconcile.js","sourceRoot":"","sources":["../../src/storage/folder-reconcile.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"folder-reconcile.js","sourceRoot":"","sources":["../../src/storage/folder-reconcile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAkBH;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAwB,EACxB,OAAsB,EACtB,MAAM,GAA2C,KAAK,IAAI,EAAE,CAAC,IAAI;IAEjE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC;IACpC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/D,mEAAmE;IACnE,IAAI,KAAK;QAAE,OAAO,CAAC,UAAU,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;IACrF,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,OA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EAAE,CAAC,CAAC,CAAC;IAC1E,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAAE,MAAM,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module indexeddb-adapter
|
|
3
|
-
*
|
|
3
|
+
* The browser's StorageAdapter: a key-value store and a store of versions by id.
|
|
4
4
|
*/
|
|
5
5
|
import type { StorageAdapter } from '../types.js';
|
|
6
|
-
/**
|
|
7
|
-
* Creates an IndexedDB backed storage adapter.
|
|
8
|
-
* @param dbName The name of the database (defaults to 'minca-storage')
|
|
9
|
-
* @returns A promise resolving to the StorageAdapter
|
|
10
|
-
*/
|
|
6
|
+
/** Creates an IndexedDB backed storage adapter */
|
|
11
7
|
export declare function createIndexedDBAdapter(dbName?: string): Promise<StorageAdapter>;
|
|
12
8
|
//# sourceMappingURL=indexeddb-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexeddb-adapter.d.ts","sourceRoot":"","sources":["../../src/storage/indexeddb-adapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAoB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"indexeddb-adapter.d.ts","sourceRoot":"","sources":["../../src/storage/indexeddb-adapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAoB,MAAM,aAAa,CAAC;AAUpE,kDAAkD;AAClD,wBAAsB,sBAAsB,CAAC,MAAM,SAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CA2E9F"}
|