@graffiti-garden/api 0.0.1 → 0.0.3
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 +3 -1
- package/src/api.ts +1 -1
- package/tests/index.ts +1 -0
- package/tests/{location.spec.ts → location.ts} +2 -2
- package/tsconfig.json +2 -3
- package/src/sync.ts +0 -58
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graffiti-garden/api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "The heart of Graffiti",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": "./src/index.ts",
|
|
8
9
|
"./tests": "./tests/index.ts"
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"homepage": "https://api.graffiti.garden/classes/Graffiti.html",
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/json-schema": "^7.0.15",
|
|
32
|
+
"@types/node": "^22.10.5",
|
|
31
33
|
"ajv": "^8.17.1",
|
|
32
34
|
"fast-json-patch": "^3.1.1",
|
|
33
35
|
"tslib": "^2.8.1",
|
package/src/api.ts
CHANGED
package/tests/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./location";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { it, expect } from "vitest";
|
|
2
|
-
import type {
|
|
2
|
+
import type { GraffitiFactory } from "../src/index";
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const graffitiLocationTests = (useGraffiti: GraffitiFactory) => {
|
|
5
5
|
it("url and location", async () => {
|
|
6
6
|
const graffiti = useGraffiti();
|
|
7
7
|
const location = {
|
package/tsconfig.json
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "esnext",
|
|
4
4
|
"module": "esnext",
|
|
5
|
-
"
|
|
6
|
-
"moduleResolution": "node",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
7
6
|
"strict": true,
|
|
8
7
|
"esModuleInterop": true,
|
|
9
8
|
"resolveJsonModule": true,
|
|
10
9
|
"verbatimModuleSyntax": true
|
|
11
10
|
},
|
|
12
|
-
"include": ["src"]
|
|
11
|
+
"include": ["src", "tests"]
|
|
13
12
|
}
|
package/src/sync.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { JSONSchema4 } from "json-schema";
|
|
2
|
-
import { Graffiti } from "./api";
|
|
3
|
-
import type {
|
|
4
|
-
GraffitiObject,
|
|
5
|
-
GraffitiObjectBase,
|
|
6
|
-
GraffitiSessionBase,
|
|
7
|
-
} from "./types";
|
|
8
|
-
import Ajv from "ajv";
|
|
9
|
-
import { applyPatch } from "fast-json-patch";
|
|
10
|
-
|
|
11
|
-
export abstract class GraffitiSynchronized extends Graffiti {
|
|
12
|
-
protected readonly ajv = new Ajv();
|
|
13
|
-
protected readonly changes = new EventTarget();
|
|
14
|
-
protected dispatchChanges(
|
|
15
|
-
oldObject: GraffitiObjectBase,
|
|
16
|
-
newObject?: GraffitiObjectBase,
|
|
17
|
-
) {
|
|
18
|
-
this.changes.dispatchEvent(
|
|
19
|
-
new CustomEvent("change", {
|
|
20
|
-
detail: {
|
|
21
|
-
oldObject,
|
|
22
|
-
newObject,
|
|
23
|
-
},
|
|
24
|
-
}),
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
protected abstract _patch(
|
|
29
|
-
...args: Parameters<Graffiti["patch"]>
|
|
30
|
-
): ReturnType<Graffiti["patch"]>;
|
|
31
|
-
|
|
32
|
-
async patch(
|
|
33
|
-
...args: Parameters<Graffiti["patch"]>
|
|
34
|
-
): ReturnType<Graffiti["patch"]> {
|
|
35
|
-
const oldObject = await this._patch(...args);
|
|
36
|
-
const newObject: GraffitiObjectBase = { ...oldObject, tombstone: false };
|
|
37
|
-
for (const prop of ["value", "channels", "allowed"] as const) {
|
|
38
|
-
const ops = args[0][prop];
|
|
39
|
-
if (!ops || !ops.length) continue;
|
|
40
|
-
const result = applyPatch(newObject[prop], ops, false, false).newDocument;
|
|
41
|
-
}
|
|
42
|
-
this.dispatchChanges(oldObject, newObject);
|
|
43
|
-
return oldObject;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// synchronize<Schema extends JSONSchema4>(
|
|
47
|
-
// ...args: Parameters<Graffiti["synchronize"]>
|
|
48
|
-
// ): ReturnType<Graffiti["synchronize"]> {
|
|
49
|
-
// const validate = this.ajv.compile(schema);
|
|
50
|
-
// const matchOptions = {
|
|
51
|
-
// ifModifiedSince: options?.ifModifiedSince,
|
|
52
|
-
// channels,
|
|
53
|
-
// };
|
|
54
|
-
// const repeater = new Repeater < {
|
|
55
|
-
// }
|
|
56
|
-
// GraffitiObject<Schema>>(
|
|
57
|
-
// }
|
|
58
|
-
}
|