@preprio/toolkit 0.5.0-rc.6 → 0.5.0-rc.7
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 +14 -6
- package/dist/astro/index.cjs +1 -1
- package/dist/astro/index.js +1 -1
- package/dist/{chunk-KZIRM54F.js → chunk-HVS5QLWG.js} +1 -1
- package/dist/{chunk-WHZNCYUS.js → chunk-JUXP5KRX.js} +1 -1
- package/dist/{chunk-L3SDL6MP.js → chunk-SUAFASBB.js} +1 -1
- package/dist/codegen/index.cjs +16 -13
- package/dist/codegen/index.d.cts +42 -18
- package/dist/codegen/index.d.ts +42 -18
- package/dist/codegen/index.js +15 -13
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/nextjs/components.cjs +1 -1
- package/dist/nextjs/components.js +2 -2
- package/dist/nextjs/index.cjs +1 -1
- package/dist/nextjs/index.js +1 -1
- package/dist/nextjs/live-action.js +2 -2
- package/dist/nuxt/index.cjs +1 -1
- package/dist/nuxt/index.js +1 -1
- package/dist/react/components.cjs +1 -1
- package/dist/react/components.js +1 -1
- package/dist/sveltekit/index.cjs +1 -1
- package/dist/sveltekit/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -737,12 +737,13 @@ There are three ways to get them there. Pick the first that fits your setup.
|
|
|
737
737
|
|
|
738
738
|
#### Option 1: GraphQL Codegen (recommended)
|
|
739
739
|
|
|
740
|
-
Add the `preprIds` document transform to your Codegen output. `_id`
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
740
|
+
Add the `preprIds` document transform to your Codegen output. `_id` is
|
|
741
|
+
added wherever your schema has one: on models and components, and inside
|
|
742
|
+
each member of a dynamic content field. Collections like `Pages` and unions
|
|
743
|
+
themselves never get an `_id`, so the queries stay valid. Your `.graphql`
|
|
744
|
+
files stay as they are; the generated documents and types include the field,
|
|
745
|
+
at no runtime cost. Adding a field never breaks code that compiles today, so
|
|
746
|
+
this is safe to turn on in an existing project.
|
|
746
747
|
|
|
747
748
|
```ts
|
|
748
749
|
// codegen.ts
|
|
@@ -766,6 +767,13 @@ export default config;
|
|
|
766
767
|
Run Codegen again after adding it. Needs `graphql` 16 or later, which a
|
|
767
768
|
Codegen setup already has.
|
|
768
769
|
|
|
770
|
+
To add `__typename` everywhere too, use `createPreprIds({ typename: true })`
|
|
771
|
+
instead. It is off by default because a selected `__typename` changes the
|
|
772
|
+
generated types: each member of a union is typed on its own, so code that
|
|
773
|
+
reads a union's fields without checking `__typename` first stops compiling.
|
|
774
|
+
Live preview only needs it on dynamic content entries, where you select it
|
|
775
|
+
already to render them.
|
|
776
|
+
|
|
769
777
|
#### Option 2: at runtime, without Codegen
|
|
770
778
|
|
|
771
779
|
`addPreprIds(document, schema)` does the same to a parsed query. It needs
|
package/dist/astro/index.cjs
CHANGED
package/dist/astro/index.js
CHANGED
package/dist/codegen/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var codegen_exports = {};
|
|
22
22
|
__export(codegen_exports, {
|
|
23
23
|
addPreprIds: () => addPreprIds,
|
|
24
|
+
createPreprIds: () => createPreprIds,
|
|
24
25
|
preprIds: () => preprIds
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(codegen_exports);
|
|
@@ -33,7 +34,8 @@ function hasResponseKey(set, key) {
|
|
|
33
34
|
(s) => s.kind === import_graphql.Kind.FIELD && (s.alias ?? s.name).value === key
|
|
34
35
|
);
|
|
35
36
|
}
|
|
36
|
-
function addPreprIds(document, schema) {
|
|
37
|
+
function addPreprIds(document, schema, options = {}) {
|
|
38
|
+
const typename = options.typename ?? false;
|
|
37
39
|
const roots = new Set(
|
|
38
40
|
[
|
|
39
41
|
schema.getQueryType(),
|
|
@@ -52,7 +54,7 @@ function addPreprIds(document, schema) {
|
|
|
52
54
|
if (((0, import_graphql.isObjectType)(type) || (0, import_graphql.isInterfaceType)(type)) && "_id" in type.getFields() && !hasResponseKey(node, "_id")) {
|
|
53
55
|
added.push(field("_id"));
|
|
54
56
|
}
|
|
55
|
-
if (!hasResponseKey(node, "__typename")) {
|
|
57
|
+
if (typename && !hasResponseKey(node, "__typename")) {
|
|
56
58
|
added.push(field("__typename"));
|
|
57
59
|
}
|
|
58
60
|
if (!added.length) return;
|
|
@@ -61,19 +63,20 @@ function addPreprIds(document, schema) {
|
|
|
61
63
|
})
|
|
62
64
|
);
|
|
63
65
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
documents,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
function createPreprIds(options = {}) {
|
|
67
|
+
return {
|
|
68
|
+
transform({ documents, schema }) {
|
|
69
|
+
const built = (0, import_graphql.buildASTSchema)(schema, { assumeValidSDL: true });
|
|
70
|
+
return documents.map(
|
|
71
|
+
(file) => file.document ? { ...file, document: addPreprIds(file.document, built, options) } : file
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var preprIds = createPreprIds();
|
|
75
77
|
// Annotate the CommonJS export names for ESM import in node:
|
|
76
78
|
0 && (module.exports = {
|
|
77
79
|
addPreprIds,
|
|
80
|
+
createPreprIds,
|
|
78
81
|
preprIds
|
|
79
82
|
});
|
package/dist/codegen/index.d.cts
CHANGED
|
@@ -6,23 +6,50 @@ import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
|
6
6
|
*/
|
|
7
7
|
interface CodegenDocumentFile {
|
|
8
8
|
document?: DocumentNode;
|
|
9
|
-
|
|
9
|
+
}
|
|
10
|
+
interface PreprIdsOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Also select `__typename` on every object, interface and union below the
|
|
13
|
+
* root. Default `false`: a selected `__typename` changes the types Codegen
|
|
14
|
+
* generates (each union member is typed separately, and objects built by
|
|
15
|
+
* hand must carry one), which can break code that compiles today. Live
|
|
16
|
+
* preview only needs it on dynamic content entries, where you select it
|
|
17
|
+
* already to render them.
|
|
18
|
+
*/
|
|
19
|
+
typename?: boolean;
|
|
10
20
|
}
|
|
11
21
|
/**
|
|
12
|
-
* Select `_id`
|
|
13
|
-
*
|
|
14
|
-
* them by hand.
|
|
22
|
+
* Select `_id` on every level of a query that has one, so live preview and
|
|
23
|
+
* click-to-edit can find each item without you selecting it by hand.
|
|
15
24
|
*
|
|
16
|
-
* The schema decides where
|
|
17
|
-
* (models and components, not collections like `Pages` or unions
|
|
18
|
-
*
|
|
19
|
-
*
|
|
25
|
+
* The schema decides where it goes: only on types that have an `_id`
|
|
26
|
+
* (models and components, not collections like `Pages` or unions; inside a
|
|
27
|
+
* union, on each member). Adding a field never breaks the types Codegen
|
|
28
|
+
* generates. With `typename: true`, `__typename` is added on every object,
|
|
29
|
+
* interface and union below the root too. Fields already selected are left
|
|
30
|
+
* as they are.
|
|
20
31
|
*/
|
|
21
|
-
declare function addPreprIds(document: DocumentNode, schema: GraphQLSchema): DocumentNode;
|
|
32
|
+
declare function addPreprIds(document: DocumentNode, schema: GraphQLSchema, options?: PreprIdsOptions): DocumentNode;
|
|
33
|
+
/** A GraphQL Codegen document transform. */
|
|
34
|
+
interface CodegenDocumentTransform {
|
|
35
|
+
transform<File extends CodegenDocumentFile>(options: {
|
|
36
|
+
documents: File[];
|
|
37
|
+
schema: DocumentNode;
|
|
38
|
+
}): File[];
|
|
39
|
+
}
|
|
22
40
|
/**
|
|
23
41
|
* GraphQL Codegen document transform that runs `addPreprIds` on every
|
|
24
|
-
* document,
|
|
25
|
-
*
|
|
42
|
+
* document, with options:
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* documentTransforms: [createPreprIds({ typename: true })],
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function createPreprIds(options?: PreprIdsOptions): CodegenDocumentTransform;
|
|
49
|
+
/**
|
|
50
|
+
* GraphQL Codegen document transform that runs `addPreprIds` on every
|
|
51
|
+
* document, so the generated documents and types include `_id` wherever the
|
|
52
|
+
* schema has one:
|
|
26
53
|
*
|
|
27
54
|
* ```ts
|
|
28
55
|
* // codegen.ts
|
|
@@ -35,12 +62,9 @@ declare function addPreprIds(document: DocumentNode, schema: GraphQLSchema): Doc
|
|
|
35
62
|
* },
|
|
36
63
|
* },
|
|
37
64
|
* ```
|
|
65
|
+
*
|
|
66
|
+
* `createPreprIds({ typename: true })` adds `__typename` as well.
|
|
38
67
|
*/
|
|
39
|
-
declare const preprIds:
|
|
40
|
-
transform({ documents, schema, }: {
|
|
41
|
-
documents: CodegenDocumentFile[];
|
|
42
|
-
schema: DocumentNode;
|
|
43
|
-
}): CodegenDocumentFile[];
|
|
44
|
-
};
|
|
68
|
+
declare const preprIds: CodegenDocumentTransform;
|
|
45
69
|
|
|
46
|
-
export { type CodegenDocumentFile, addPreprIds, preprIds };
|
|
70
|
+
export { type CodegenDocumentFile, type CodegenDocumentTransform, type PreprIdsOptions, addPreprIds, createPreprIds, preprIds };
|
package/dist/codegen/index.d.ts
CHANGED
|
@@ -6,23 +6,50 @@ import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
|
6
6
|
*/
|
|
7
7
|
interface CodegenDocumentFile {
|
|
8
8
|
document?: DocumentNode;
|
|
9
|
-
|
|
9
|
+
}
|
|
10
|
+
interface PreprIdsOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Also select `__typename` on every object, interface and union below the
|
|
13
|
+
* root. Default `false`: a selected `__typename` changes the types Codegen
|
|
14
|
+
* generates (each union member is typed separately, and objects built by
|
|
15
|
+
* hand must carry one), which can break code that compiles today. Live
|
|
16
|
+
* preview only needs it on dynamic content entries, where you select it
|
|
17
|
+
* already to render them.
|
|
18
|
+
*/
|
|
19
|
+
typename?: boolean;
|
|
10
20
|
}
|
|
11
21
|
/**
|
|
12
|
-
* Select `_id`
|
|
13
|
-
*
|
|
14
|
-
* them by hand.
|
|
22
|
+
* Select `_id` on every level of a query that has one, so live preview and
|
|
23
|
+
* click-to-edit can find each item without you selecting it by hand.
|
|
15
24
|
*
|
|
16
|
-
* The schema decides where
|
|
17
|
-
* (models and components, not collections like `Pages` or unions
|
|
18
|
-
*
|
|
19
|
-
*
|
|
25
|
+
* The schema decides where it goes: only on types that have an `_id`
|
|
26
|
+
* (models and components, not collections like `Pages` or unions; inside a
|
|
27
|
+
* union, on each member). Adding a field never breaks the types Codegen
|
|
28
|
+
* generates. With `typename: true`, `__typename` is added on every object,
|
|
29
|
+
* interface and union below the root too. Fields already selected are left
|
|
30
|
+
* as they are.
|
|
20
31
|
*/
|
|
21
|
-
declare function addPreprIds(document: DocumentNode, schema: GraphQLSchema): DocumentNode;
|
|
32
|
+
declare function addPreprIds(document: DocumentNode, schema: GraphQLSchema, options?: PreprIdsOptions): DocumentNode;
|
|
33
|
+
/** A GraphQL Codegen document transform. */
|
|
34
|
+
interface CodegenDocumentTransform {
|
|
35
|
+
transform<File extends CodegenDocumentFile>(options: {
|
|
36
|
+
documents: File[];
|
|
37
|
+
schema: DocumentNode;
|
|
38
|
+
}): File[];
|
|
39
|
+
}
|
|
22
40
|
/**
|
|
23
41
|
* GraphQL Codegen document transform that runs `addPreprIds` on every
|
|
24
|
-
* document,
|
|
25
|
-
*
|
|
42
|
+
* document, with options:
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* documentTransforms: [createPreprIds({ typename: true })],
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function createPreprIds(options?: PreprIdsOptions): CodegenDocumentTransform;
|
|
49
|
+
/**
|
|
50
|
+
* GraphQL Codegen document transform that runs `addPreprIds` on every
|
|
51
|
+
* document, so the generated documents and types include `_id` wherever the
|
|
52
|
+
* schema has one:
|
|
26
53
|
*
|
|
27
54
|
* ```ts
|
|
28
55
|
* // codegen.ts
|
|
@@ -35,12 +62,9 @@ declare function addPreprIds(document: DocumentNode, schema: GraphQLSchema): Doc
|
|
|
35
62
|
* },
|
|
36
63
|
* },
|
|
37
64
|
* ```
|
|
65
|
+
*
|
|
66
|
+
* `createPreprIds({ typename: true })` adds `__typename` as well.
|
|
38
67
|
*/
|
|
39
|
-
declare const preprIds:
|
|
40
|
-
transform({ documents, schema, }: {
|
|
41
|
-
documents: CodegenDocumentFile[];
|
|
42
|
-
schema: DocumentNode;
|
|
43
|
-
}): CodegenDocumentFile[];
|
|
44
|
-
};
|
|
68
|
+
declare const preprIds: CodegenDocumentTransform;
|
|
45
69
|
|
|
46
|
-
export { type CodegenDocumentFile, addPreprIds, preprIds };
|
|
70
|
+
export { type CodegenDocumentFile, type CodegenDocumentTransform, type PreprIdsOptions, addPreprIds, createPreprIds, preprIds };
|
package/dist/codegen/index.js
CHANGED
|
@@ -17,7 +17,8 @@ function hasResponseKey(set, key) {
|
|
|
17
17
|
(s) => s.kind === Kind.FIELD && (s.alias ?? s.name).value === key
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
|
-
function addPreprIds(document, schema) {
|
|
20
|
+
function addPreprIds(document, schema, options = {}) {
|
|
21
|
+
const typename = options.typename ?? false;
|
|
21
22
|
const roots = new Set(
|
|
22
23
|
[
|
|
23
24
|
schema.getQueryType(),
|
|
@@ -36,7 +37,7 @@ function addPreprIds(document, schema) {
|
|
|
36
37
|
if ((isObjectType(type) || isInterfaceType(type)) && "_id" in type.getFields() && !hasResponseKey(node, "_id")) {
|
|
37
38
|
added.push(field("_id"));
|
|
38
39
|
}
|
|
39
|
-
if (!hasResponseKey(node, "__typename")) {
|
|
40
|
+
if (typename && !hasResponseKey(node, "__typename")) {
|
|
40
41
|
added.push(field("__typename"));
|
|
41
42
|
}
|
|
42
43
|
if (!added.length) return;
|
|
@@ -45,18 +46,19 @@ function addPreprIds(document, schema) {
|
|
|
45
46
|
})
|
|
46
47
|
);
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
documents,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
function createPreprIds(options = {}) {
|
|
50
|
+
return {
|
|
51
|
+
transform({ documents, schema }) {
|
|
52
|
+
const built = buildASTSchema(schema, { assumeValidSDL: true });
|
|
53
|
+
return documents.map(
|
|
54
|
+
(file) => file.document ? { ...file, document: addPreprIds(file.document, built, options) } : file
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
var preprIds = createPreprIds();
|
|
59
60
|
export {
|
|
60
61
|
addPreprIds,
|
|
62
|
+
createPreprIds,
|
|
61
63
|
preprIds
|
|
62
64
|
};
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j
|
|
|
5
5
|
* Package version; must match package.json. Lives in its own leaf module so
|
|
6
6
|
* core can import it without cycling through the barrel.
|
|
7
7
|
*/
|
|
8
|
-
declare const VERSION = "0.5.0-rc.
|
|
8
|
+
declare const VERSION = "0.5.0-rc.7";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j
|
|
|
5
5
|
* Package version; must match package.json. Lives in its own leaf module so
|
|
6
6
|
* core can import it without cycling through the barrel.
|
|
7
7
|
*/
|
|
8
|
-
declare const VERSION = "0.5.0-rc.
|
|
8
|
+
declare const VERSION = "0.5.0-rc.7";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
setTrackingParam,
|
|
18
18
|
stegaClean,
|
|
19
19
|
trackEvent
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-SUAFASBB.js";
|
|
21
21
|
import {
|
|
22
22
|
PreprError,
|
|
23
23
|
extractAccessToken,
|
|
@@ -28,11 +28,11 @@ import {
|
|
|
28
28
|
getPreprUUIDFromHeaders,
|
|
29
29
|
getToolbarPropsFromHeaders,
|
|
30
30
|
validatePreprToken
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-HVS5QLWG.js";
|
|
32
32
|
import {
|
|
33
33
|
VERSION,
|
|
34
34
|
resolveFeatures
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-JUXP5KRX.js";
|
|
36
36
|
import {
|
|
37
37
|
createLiveBridge,
|
|
38
38
|
createLiveStore
|
|
@@ -3525,7 +3525,7 @@ function createPreprPreview(opts = {}) {
|
|
|
3525
3525
|
var import_react = require("react");
|
|
3526
3526
|
|
|
3527
3527
|
// src/version.ts
|
|
3528
|
-
var VERSION = "0.5.0-rc.
|
|
3528
|
+
var VERSION = "0.5.0-rc.7";
|
|
3529
3529
|
|
|
3530
3530
|
// src/core/pixel.ts
|
|
3531
3531
|
var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
|
package/dist/nextjs/index.cjs
CHANGED
|
@@ -49,7 +49,7 @@ module.exports = __toCommonJS(nextjs_exports);
|
|
|
49
49
|
var import_server = require("next/server");
|
|
50
50
|
|
|
51
51
|
// src/version.ts
|
|
52
|
-
var VERSION = "0.5.0-rc.
|
|
52
|
+
var VERSION = "0.5.0-rc.7";
|
|
53
53
|
|
|
54
54
|
// src/core/constants.ts
|
|
55
55
|
var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
|
package/dist/nextjs/index.js
CHANGED
package/dist/nuxt/index.cjs
CHANGED
package/dist/nuxt/index.js
CHANGED
|
@@ -3521,7 +3521,7 @@ function createPreprPreview(opts = {}) {
|
|
|
3521
3521
|
}
|
|
3522
3522
|
|
|
3523
3523
|
// src/version.ts
|
|
3524
|
-
var VERSION = "0.5.0-rc.
|
|
3524
|
+
var VERSION = "0.5.0-rc.7";
|
|
3525
3525
|
|
|
3526
3526
|
// src/core/pixel.ts
|
|
3527
3527
|
var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
|
package/dist/react/components.js
CHANGED
|
@@ -3497,7 +3497,7 @@ function createPreprPreview(opts = {}) {
|
|
|
3497
3497
|
}
|
|
3498
3498
|
|
|
3499
3499
|
// src/version.ts
|
|
3500
|
-
var VERSION = "0.5.0-rc.
|
|
3500
|
+
var VERSION = "0.5.0-rc.7";
|
|
3501
3501
|
|
|
3502
3502
|
// src/core/pixel.ts
|
|
3503
3503
|
var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
|
package/dist/sveltekit/index.cjs
CHANGED
package/dist/sveltekit/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preprio/toolkit",
|
|
3
|
-
"version": "0.5.0-rc.
|
|
3
|
+
"version": "0.5.0-rc.7",
|
|
4
4
|
"description": "Prepr personalization, A/B testing and preview toolkit for React, Next.js, Nuxt, Astro, SvelteKit and Express",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Prepr B.V. (https://prepr.io)",
|