-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(json-crdt): 🎸 use Extension class to construct extensions
- Loading branch information
Showing
17 changed files
with
90 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {cnt} from './cnt'; | ||
import {mval} from './mval'; | ||
import {peritext} from './peritext'; | ||
|
||
export { | ||
cnt, | ||
mval, | ||
peritext, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export * from './mval'; | ||
export * from './cnt'; | ||
export * from './peritext'; | ||
export * from './ext'; | ||
export * from './ModelWithExt'; | ||
export * from './constants'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import {ExtensionId} from '../constants'; | ||
import {PeritextNode} from './PeritextNode'; | ||
import {PeritextApi} from './PeritextApi'; | ||
import {BUILD_SCHEMA, MNEMONIC} from './constants'; | ||
import {SCHEMA, MNEMONIC} from './constants'; | ||
import {Extension} from '../../json-crdt/extensions/Extension'; | ||
import type {PeritextDataNode} from './types'; | ||
import {s, type ExtensionDefinition} from '../../json-crdt'; | ||
|
||
export const PeritextExt: ExtensionDefinition<PeritextDataNode, PeritextNode, PeritextApi> = { | ||
id: ExtensionId.peritext, | ||
name: MNEMONIC, | ||
new: (text: string) => s.ext(ExtensionId.peritext, BUILD_SCHEMA(text)), | ||
Node: PeritextNode, | ||
Api: PeritextApi, | ||
}; | ||
export const peritext = new Extension< | ||
ExtensionId.peritext, | ||
PeritextDataNode, | ||
PeritextNode, | ||
PeritextApi, | ||
[text: string] | ||
>(ExtensionId.peritext, MNEMONIC, PeritextNode, PeritextApi, (text: string) => SCHEMA(text)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
import {s, type NodeBuilder, type nodes} from '../../json-crdt-patch'; | ||
import {NodeBuilder, s, type nodes} from '../../json-crdt-patch'; | ||
import type {ModelApi} from '../model'; | ||
import type {JsonNode} from '../nodes'; | ||
import type {JsonNodeToSchema} from '../schema/types'; | ||
import type {ExtensionApi, ExtensionJsonNode} from './types'; | ||
|
||
export type AnyExtension = Extension<any, any, any, any, any, any>; | ||
|
||
export class Extension< | ||
Id extends number, | ||
Node extends JsonNode, | ||
ENode extends ExtensionJsonNode, | ||
EApi extends ExtensionApi<ENode>, | ||
ESchema extends NodeBuilder, | ||
DataNode extends JsonNode, | ||
ExtNode extends ExtensionJsonNode<DataNode>, | ||
ExtApi extends ExtensionApi<ExtNode>, | ||
DataArgs extends any[] = any[], | ||
DataSchema extends NodeBuilder = JsonNodeToSchema<DataNode>, | ||
> { | ||
constructor( | ||
public readonly id: Id, | ||
public readonly name: string, | ||
public readonly schema: (...args: any[]) => ESchema, | ||
public readonly Node: new (data: Node) => ENode, | ||
public readonly Api: new (node: ENode, api: ModelApi) => EApi, | ||
public readonly Node: new (data: DataNode) => ExtNode, | ||
public readonly Api: new (node: ExtNode, api: ModelApi) => ExtApi, | ||
public readonly schema: (...args: DataArgs) => DataSchema, | ||
) {} | ||
|
||
public new(...args: any[]): nodes.ext<Id, ESchema> { | ||
return s.ext<Id, ESchema>(this.id, this.schema(...args)); | ||
public new(...args: DataArgs): nodes.ext<Id, DataSchema> { | ||
return s.ext<Id, DataSchema>(this.id, this.schema(...args)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,9 @@ | ||
import type {NodeBuilder} from '../../json-crdt-patch/builder/DelayedValueBuilder'; | ||
import type {ModelApi} from '../model/api/ModelApi'; | ||
import type {NodeApi} from '../model/api/nodes'; | ||
import type {JsonNode} from '../nodes'; | ||
import type {ExtensionNode} from './ExtensionNode'; | ||
|
||
export type ExtensionValue = [type: Uint8Array, data: unknown]; | ||
|
||
export interface ExtensionJsonNode extends JsonNode {} | ||
export interface ExtensionJsonNode<N extends JsonNode> extends ExtensionNode<N> {} | ||
|
||
export interface ExtensionApi<EN extends ExtensionJsonNode> extends NodeApi<EN> {} | ||
|
||
export interface ExtensionDefinition< | ||
Node extends JsonNode = JsonNode, | ||
ENode extends ExtensionJsonNode = ExtensionJsonNode, | ||
EApi extends ExtensionApi<ENode> = ExtensionApi<ENode>, | ||
ESchema extends NodeBuilder = NodeBuilder, | ||
> { | ||
id: number; | ||
name: string; | ||
new: (...args: any[]) => ESchema; | ||
Node: new (data: Node) => ENode; | ||
Api: new (node: ENode, api: ModelApi) => EApi; | ||
} | ||
export interface ExtensionApi<EN extends ExtensionJsonNode<any>> extends NodeApi<EN> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters