@dappermountain/payload-plugin-achievements 1.0.0-beta.1 → 1.0.0-beta.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/README.md +2 -2
- package/dist/collections/Achievements/index.js +2 -2
- package/dist/collections/Tiers/index.js +1 -1
- package/dist/collections/fields/index.d.ts +1 -1
- package/dist/collections/fields/index.d.ts.map +1 -1
- package/dist/collections/fields/index.js +1 -1
- package/dist/collections/fields/ruleFields.d.ts +25 -2
- package/dist/collections/fields/ruleFields.d.ts.map +1 -1
- package/dist/collections/fields/ruleFields.js +39 -3
- package/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ You describe what people can earn and what has to happen first. Your app records
|
|
|
18
18
|
|
|
19
19
|
| Plugin line | Payload | Notes |
|
|
20
20
|
| ----------- | ------- | ----- |
|
|
21
|
-
| **`1.x`** (this package — e.g. `1.0.0-beta.
|
|
21
|
+
| **`1.x`** (this package — e.g. `1.0.0-beta.2`) | **4** (`^4.0.0-beta.1` / `^4.0.0`) | Current line. Opt out of P4 default versions/authorship on high-churn collections. |
|
|
22
22
|
| **`0.6.x`** | **3** (`^3.89`) | Last Payload 3 line. Same product features (reactions, composites, etc.). Stay on `0.6.x` until you upgrade the host to Payload 4. |
|
|
23
23
|
|
|
24
24
|
One published version cannot peer both Payload majors (Admin field types and collection defaults diverge). Pick the line that matches your host.
|
|
@@ -37,7 +37,7 @@ Plugin collections opt out of Payload 4’s default versions and authorship (app
|
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
39
|
# Payload 4 hosts
|
|
40
|
-
bun add @dappermountain/payload-plugin-achievements@^1.0.0-beta.
|
|
40
|
+
bun add @dappermountain/payload-plugin-achievements@^1.0.0-beta.2
|
|
41
41
|
|
|
42
42
|
# Payload 3 hosts (stay on the 0.6 line)
|
|
43
43
|
bun add @dappermountain/payload-plugin-achievements@0.6
|
|
@@ -49,7 +49,7 @@ export function buildAchievementsCollection() {
|
|
|
49
49
|
admin: {
|
|
50
50
|
description: 'Who may request this achievement. Composed parents that auto-grant should leave this empty.',
|
|
51
51
|
},
|
|
52
|
-
fields: buildRuleTreeFields(),
|
|
52
|
+
fields: buildRuleTreeFields({ dbName: 'ach_elig_r' }),
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
name: 'completionRules',
|
|
@@ -58,7 +58,7 @@ export function buildAchievementsCollection() {
|
|
|
58
58
|
admin: {
|
|
59
59
|
description: 'What this achievement is made of. When every rule passes, it is granted automatically (do not require review on composed parents). Nested achievements appear in this order in your app UI.',
|
|
60
60
|
},
|
|
61
|
-
fields: buildRuleTreeFields(),
|
|
61
|
+
fields: buildRuleTreeFields({ dbName: 'ach_comp_r' }),
|
|
62
62
|
},
|
|
63
63
|
],
|
|
64
64
|
};
|
|
@@ -85,7 +85,7 @@ export function buildTiersCollection() {
|
|
|
85
85
|
admin: {
|
|
86
86
|
description: 'Rules that must pass to unlock this tier (all-of or any-of). Empty rules mean this step is open. Current tier is derived by walking ranks; optional tier.changed logs record moves.',
|
|
87
87
|
},
|
|
88
|
-
fields: buildRuleTreeFields(),
|
|
88
|
+
fields: buildRuleTreeFields({ dbName: 'ach_unlk_r' }),
|
|
89
89
|
},
|
|
90
90
|
],
|
|
91
91
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { scopeField } from './scopeField.js';
|
|
2
2
|
export { userField } from './userField.js';
|
|
3
|
-
export { buildRuleRowFields, buildRuleTreeFields } from './ruleFields.js';
|
|
3
|
+
export { assertSafeRuleArrayDbName, buildRuleRowFields, buildRuleTreeFields, POSTGRES_IDENTIFIER_MAX, ruleArrayIdentifierLength, type BuildRuleTreeFieldsArgs, } from './ruleFields.js';
|
|
4
4
|
export { usersAchievementsGroup } from './usersAchievementsGroup.js';
|
|
5
5
|
export { localizedDescriptionField, localizedNameField } from './localizedText.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EACL,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,yBAAyB,EACzB,KAAK,uBAAuB,GAC7B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACpE,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { scopeField } from './scopeField.js';
|
|
2
2
|
export { userField } from './userField.js';
|
|
3
|
-
export { buildRuleRowFields, buildRuleTreeFields } from './ruleFields.js';
|
|
3
|
+
export { assertSafeRuleArrayDbName, buildRuleRowFields, buildRuleTreeFields, POSTGRES_IDENTIFIER_MAX, ruleArrayIdentifierLength, } from './ruleFields.js';
|
|
4
4
|
export { usersAchievementsGroup } from './usersAchievementsGroup.js';
|
|
5
5
|
export { localizedDescriptionField, localizedNameField } from './localizedText.js';
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
import type { Field } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Postgres truncates identifiers over 63 chars. Nested `rules` arrays under
|
|
4
|
+
* `eligibilityRules` / `completionRules` / `unlockRules` exceed that when
|
|
5
|
+
* Payload auto-names tables — set explicit short `dbName` values instead.
|
|
6
|
+
*
|
|
7
|
+
* Call sites must pass a **unique** `dbName` (plugin-wide). Nested group rules
|
|
8
|
+
* use `${dbName}_g` so one prefix yields two unique table names.
|
|
9
|
+
*/
|
|
10
|
+
export declare const POSTGRES_IDENTIFIER_MAX = 63;
|
|
11
|
+
export type BuildRuleTreeFieldsArgs = {
|
|
12
|
+
/**
|
|
13
|
+
* Short, unique Postgres table name for the outer `rules` array.
|
|
14
|
+
* Nested group `rules` become `${dbName}_g`. Must stay unique across the plugin.
|
|
15
|
+
*/
|
|
16
|
+
dbName: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Worst-case identifier length when Payload prefixes `dbName` with the parent
|
|
20
|
+
* collection table and appends `_parent_id_idx` / `_parent_id_fk`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ruleArrayIdentifierLength(dbName: string, parentTable?: string): number;
|
|
23
|
+
export declare function assertSafeRuleArrayDbName(dbName: string): void;
|
|
2
24
|
/**
|
|
3
25
|
* Top-level rule group: combinator + rules, with one nested group level.
|
|
26
|
+
* Pass a unique short {@link BuildRuleTreeFieldsArgs.dbName} per embed site.
|
|
4
27
|
*/
|
|
5
|
-
export declare function buildRuleTreeFields(): Field[];
|
|
28
|
+
export declare function buildRuleTreeFields(args: BuildRuleTreeFieldsArgs): Field[];
|
|
6
29
|
/** @deprecated Use {@link buildRuleTreeFields}. */
|
|
7
|
-
export declare function buildRuleRowFields(): Field[];
|
|
30
|
+
export declare function buildRuleRowFields(args: BuildRuleTreeFieldsArgs): Field[];
|
|
8
31
|
//# sourceMappingURL=ruleFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ruleFields.d.ts","sourceRoot":"","sources":["../../../src/collections/fields/ruleFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAU,MAAM,SAAS,CAAA;AAqI5C
|
|
1
|
+
{"version":3,"file":"ruleFields.d.ts","sourceRoot":"","sources":["../../../src/collections/fields/ruleFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAU,MAAM,SAAS,CAAA;AAqI5C;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAA;AAUzC,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,SAA+B,GAAG,MAAM,CAE5G;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAY9D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,uBAAuB,GAAG,KAAK,EAAE,CA2B1E;AAED,mDAAmD;AACnD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,uBAAuB,GAAG,KAAK,EAAE,CAEzE"}
|
|
@@ -121,15 +121,50 @@ function ruleParamFields() {
|
|
|
121
121
|
function buildRuleLeafFields() {
|
|
122
122
|
return [ruleTypeSelect(false), ...ruleParamFields()];
|
|
123
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Postgres truncates identifiers over 63 chars. Nested `rules` arrays under
|
|
126
|
+
* `eligibilityRules` / `completionRules` / `unlockRules` exceed that when
|
|
127
|
+
* Payload auto-names tables — set explicit short `dbName` values instead.
|
|
128
|
+
*
|
|
129
|
+
* Call sites must pass a **unique** `dbName` (plugin-wide). Nested group rules
|
|
130
|
+
* use `${dbName}_g` so one prefix yields two unique table names.
|
|
131
|
+
*/
|
|
132
|
+
export const POSTGRES_IDENTIFIER_MAX = 63;
|
|
133
|
+
/** Longest default plugin table (`achievement-definitions` → snake_case). */
|
|
134
|
+
const LONGEST_DEFAULT_PARENT_TABLE = 'achievement_definitions';
|
|
135
|
+
const PARENT_ID_INDEX_SUFFIX = '_parent_id_idx';
|
|
136
|
+
/** Nested group-rules array suffix; keep short and stable. */
|
|
137
|
+
const NESTED_RULES_DB_SUFFIX = '_g';
|
|
138
|
+
/**
|
|
139
|
+
* Worst-case identifier length when Payload prefixes `dbName` with the parent
|
|
140
|
+
* collection table and appends `_parent_id_idx` / `_parent_id_fk`.
|
|
141
|
+
*/
|
|
142
|
+
export function ruleArrayIdentifierLength(dbName, parentTable = LONGEST_DEFAULT_PARENT_TABLE) {
|
|
143
|
+
return parentTable.length + 1 + dbName.length + PARENT_ID_INDEX_SUFFIX.length;
|
|
144
|
+
}
|
|
145
|
+
export function assertSafeRuleArrayDbName(dbName) {
|
|
146
|
+
if (!/^[a-z][a-z0-9_]*$/.test(dbName)) {
|
|
147
|
+
throw new Error(`Rule array dbName "${dbName}" must be a lowercase snake_case Postgres identifier starting with a letter.`);
|
|
148
|
+
}
|
|
149
|
+
const length = ruleArrayIdentifierLength(dbName);
|
|
150
|
+
if (length > POSTGRES_IDENTIFIER_MAX) {
|
|
151
|
+
throw new Error(`Rule array dbName "${dbName}" is too long (${length} > ${POSTGRES_IDENTIFIER_MAX} with parent index suffix).`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
124
154
|
/**
|
|
125
155
|
* Top-level rule group: combinator + rules, with one nested group level.
|
|
156
|
+
* Pass a unique short {@link BuildRuleTreeFieldsArgs.dbName} per embed site.
|
|
126
157
|
*/
|
|
127
|
-
export function buildRuleTreeFields() {
|
|
158
|
+
export function buildRuleTreeFields(args) {
|
|
159
|
+
assertSafeRuleArrayDbName(args.dbName);
|
|
160
|
+
const nestedDbName = `${args.dbName}${NESTED_RULES_DB_SUFFIX}`;
|
|
161
|
+
assertSafeRuleArrayDbName(nestedDbName);
|
|
128
162
|
return [
|
|
129
163
|
combinatorField(),
|
|
130
164
|
{
|
|
131
165
|
name: 'rules',
|
|
132
166
|
type: 'array',
|
|
167
|
+
dbName: args.dbName,
|
|
133
168
|
labels: { singular: 'Rule', plural: 'Rules' },
|
|
134
169
|
fields: [
|
|
135
170
|
ruleTypeSelect(true),
|
|
@@ -138,6 +173,7 @@ export function buildRuleTreeFields() {
|
|
|
138
173
|
{
|
|
139
174
|
name: 'rules',
|
|
140
175
|
type: 'array',
|
|
176
|
+
dbName: nestedDbName,
|
|
141
177
|
labels: { singular: 'Rule', plural: 'Rules' },
|
|
142
178
|
admin: { condition: (_, sibling) => sibling?.type === 'group' },
|
|
143
179
|
fields: buildRuleLeafFields(),
|
|
@@ -147,6 +183,6 @@ export function buildRuleTreeFields() {
|
|
|
147
183
|
];
|
|
148
184
|
}
|
|
149
185
|
/** @deprecated Use {@link buildRuleTreeFields}. */
|
|
150
|
-
export function buildRuleRowFields() {
|
|
151
|
-
return buildRuleTreeFields();
|
|
186
|
+
export function buildRuleRowFields(args) {
|
|
187
|
+
return buildRuleTreeFields(args);
|
|
152
188
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dappermountain/payload-plugin-achievements",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"description": "A robust, Admin-configured achievements engine for Payload: composable unlock rules, derived rank progress, request/review grants, metrics, and scoped multi-tenant support.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|