Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@payloadcms/drizzle

Package Overview
Dependencies
Maintainers
0
Versions
239
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@payloadcms/drizzle - npm Package Compare versions

Comparing version 3.0.0-canary.12a836c to 3.0.0-canary.1a675ae

dist/exports/postgres.d.ts

4

dist/find/traverseFields.js

@@ -1,2 +0,2 @@

/* eslint-disable no-param-reassign */ import { fieldAffectsData, tabHasName } from 'payload/shared';
import { fieldAffectsData, tabHasName } from 'payload/shared';
import toSnakeCase from 'to-snake-case';

@@ -6,3 +6,3 @@ export const traverseFields = ({ _locales, adapter, currentArgs, currentTableName, depth, fields, path, topLevelArgs, topLevelTableName })=>{

// handle simple relationship
if (depth > 0 && (field.type === 'upload' || field.type === 'relationship' && !field.hasMany && typeof field.relationTo === 'string')) {
if (depth > 0 && (field.type === 'upload' || field.type === 'relationship') && !field.hasMany && typeof field.relationTo === 'string') {
if (field.localized) {

@@ -9,0 +9,0 @@ _locales.with[`${path}${field.name}`] = true;

@@ -352,3 +352,3 @@ import { and, eq, like, sql } from 'drizzle-orm';

const newCollectionPath = pathSegments.slice(1).join('.');
if (Array.isArray(field.relationTo) || field.type === 'relationship' && field.hasMany) {
if (Array.isArray(field.relationTo) || field.hasMany) {
let relationshipFields;

@@ -355,0 +355,0 @@ const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`;

@@ -7,5 +7,6 @@ import type { NumberField } from 'payload';

ref: Record<string, unknown>;
withinArrayOrBlockLocale?: string;
};
export declare const transformHasManyNumber: ({ field, locale, numberRows, ref }: Args) => void;
export declare const transformHasManyNumber: ({ field, locale, numberRows, ref, withinArrayOrBlockLocale, }: Args) => void;
export {};
//# sourceMappingURL=hasManyNumber.d.ts.map

@@ -1,3 +0,13 @@

/* eslint-disable no-param-reassign */ export const transformHasManyNumber = ({ field, locale, numberRows, ref })=>{
const result = numberRows.map(({ number })=>number);
export const transformHasManyNumber = ({ field, locale, numberRows, ref, withinArrayOrBlockLocale })=>{
let result;
if (withinArrayOrBlockLocale) {
result = numberRows.reduce((acc, { locale, number })=>{
if (locale === withinArrayOrBlockLocale) {
acc.push(number);
}
return acc;
}, []);
} else {
result = numberRows.map(({ number })=>number);
}
if (locale) {

@@ -4,0 +14,0 @@ ref[field.name][locale] = result;

@@ -7,5 +7,6 @@ import type { TextField } from 'payload';

textRows: Record<string, unknown>[];
withinArrayOrBlockLocale?: string;
};
export declare const transformHasManyText: ({ field, locale, ref, textRows }: Args) => void;
export declare const transformHasManyText: ({ field, locale, ref, textRows, withinArrayOrBlockLocale, }: Args) => void;
export {};
//# sourceMappingURL=hasManyText.d.ts.map

@@ -1,3 +0,13 @@

/* eslint-disable no-param-reassign */ export const transformHasManyText = ({ field, locale, ref, textRows })=>{
const result = textRows.map(({ text })=>text);
export const transformHasManyText = ({ field, locale, ref, textRows, withinArrayOrBlockLocale })=>{
let result;
if (withinArrayOrBlockLocale) {
result = textRows.reduce((acc, { locale, text })=>{
if (locale === withinArrayOrBlockLocale) {
acc.push(text);
}
return acc;
}, []);
} else {
result = textRows.map(({ text })=>text);
}
if (locale) {

@@ -4,0 +14,0 @@ ref[field.name][locale] = result;

@@ -7,5 +7,6 @@ import type { RelationshipField, UploadField } from 'payload';

relations: Record<string, unknown>[];
withinArrayOrBlockLocale?: string;
};
export declare const transformRelationship: ({ field, locale, ref, relations }: Args) => void;
export declare const transformRelationship: ({ field, locale, ref, relations, withinArrayOrBlockLocale, }: Args) => void;
export {};
//# sourceMappingURL=relationship.d.ts.map

@@ -1,9 +0,13 @@

/* eslint-disable no-param-reassign */ export const transformRelationship = ({ field, locale, ref, relations })=>{
export const transformRelationship = ({ field, locale, ref, relations, withinArrayOrBlockLocale })=>{
let result;
if (!('hasMany' in field) || field.hasMany === false) {
const relation = relations[0];
let relation = relations[0];
if (withinArrayOrBlockLocale) {
relation = relations.find((rel)=>rel.locale === withinArrayOrBlockLocale);
}
if (relation) {
// Handle hasOne Poly
if (Array.isArray(field.relationTo)) {
const matchedRelation = Object.entries(relation).find(([key, val])=>val !== null && ![
const matchedRelation = Object.entries(relation).find(([key, val])=>{
return val !== null && ![
'id',

@@ -14,3 +18,4 @@ 'locale',

'path'
].includes(key));
].includes(key);
});
if (matchedRelation) {

@@ -28,6 +33,10 @@ const relationTo = matchedRelation[0].replace('ID', '');

relations.forEach((relation)=>{
let matchedLocale = true;
if (withinArrayOrBlockLocale) {
matchedLocale = relation.locale === withinArrayOrBlockLocale;
}
// Handle hasMany
if (!Array.isArray(field.relationTo)) {
const relatedData = relation[`${field.relationTo}ID`];
if (relatedData) {
if (relatedData && matchedLocale) {
transformedRelations.push(relatedData);

@@ -43,3 +52,3 @@ }

'path'
].includes(key));
].includes(key) && matchedLocale);
if (matchedRelation) {

@@ -46,0 +55,0 @@ const relationTo = matchedRelation[0].replace('ID', '');

@@ -53,5 +53,9 @@ import type { Field, SanitizedConfig, TabAsField } from 'payload';

texts: Record<string, Record<string, unknown>[]>;
/**
* Set to a locale if this group of fields is within a localized array or block.
*/
withinArrayOrBlockLocale?: string;
};
export declare const traverseFields: <T extends Record<string, unknown>>({ adapter, blocks, config, dataRef, deletions, fieldPrefix, fields, numbers, path, relationships, table, texts, }: TraverseFieldsArgs) => T;
export declare const traverseFields: <T extends Record<string, unknown>>({ adapter, blocks, config, dataRef, deletions, fieldPrefix, fields, numbers, path, relationships, table, texts, withinArrayOrBlockLocale, }: TraverseFieldsArgs) => T;
export {};
//# sourceMappingURL=traverseFields.d.ts.map

@@ -7,3 +7,3 @@ import { fieldAffectsData } from 'payload/shared';

// for each field type into required Payload shape
export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fieldPrefix, fields, numbers, path, relationships, table, texts })=>{
export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fieldPrefix, fields, numbers, path, relationships, table, texts, withinArrayOrBlockLocale })=>{
const sanitizedPath = path ? `${path}.` : path;

@@ -27,3 +27,4 @@ const formatted = fields.reduce((result, field)=>{

table,
texts
texts,
withinArrayOrBlockLocale
});

@@ -44,3 +45,4 @@ }

table,
texts
texts,
withinArrayOrBlockLocale
});

@@ -81,3 +83,4 @@ }

table: row,
texts
texts,
withinArrayOrBlockLocale: locale
});

@@ -112,3 +115,4 @@ if ('_order' in rowResult) {

table: row,
texts
texts,
withinArrayOrBlockLocale
});

@@ -152,3 +156,4 @@ });

table: row,
texts
texts,
withinArrayOrBlockLocale: locale
});

@@ -162,3 +167,3 @@ delete blockResult._order;

} else {
result[field.name] = blocks[blockFieldPath].map((row, i)=>{
result[field.name] = blocks[blockFieldPath].reduce((acc, row, i)=>{
delete row._order;

@@ -171,19 +176,28 @@ if (row._uuid) {

if (block) {
return traverseFields({
adapter,
blocks,
config,
dataRef: row,
deletions,
fieldPrefix: '',
fields: block.fields,
numbers,
path: `${blockFieldPath}.${i}`,
relationships,
table: row,
texts
});
if (!withinArrayOrBlockLocale || withinArrayOrBlockLocale && withinArrayOrBlockLocale === row._locale) {
if (row._locale) {
delete row._locale;
}
acc.push(traverseFields({
adapter,
blocks,
config,
dataRef: row,
deletions,
fieldPrefix: '',
fields: block.fields,
numbers,
path: `${blockFieldPath}.${i}`,
relationships,
table: row,
texts,
withinArrayOrBlockLocale
}));
return acc;
}
} else {
acc.push({});
}
return {};
});
return acc;
}, []);
}

@@ -242,3 +256,4 @@ }

ref: result,
relations: relationPathMatch
relations: relationPathMatch,
withinArrayOrBlockLocale
});

@@ -273,3 +288,4 @@ }

ref: result,
textRows: textPathMatch
textRows: textPathMatch,
withinArrayOrBlockLocale
});

@@ -303,3 +319,4 @@ }

numberRows: numberPathMatch,
ref: result
ref: result,
withinArrayOrBlockLocale
});

@@ -365,3 +382,4 @@ }

table,
texts
texts,
withinArrayOrBlockLocale
});

@@ -368,0 +386,0 @@ if ('_order' in ref) {

@@ -23,5 +23,10 @@ import type { ArrayField } from 'payload';

texts: Record<string, unknown>[];
/**
* Set to a locale code if this set of fields is traversed within a
* localized array or block field
*/
withinArrayOrBlockLocale?: string;
};
export declare const transformArray: ({ adapter, arrayTableName, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts, }: Args) => ArrayRowToInsert[];
export declare const transformArray: ({ adapter, arrayTableName, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale, }: Args) => ArrayRowToInsert[];
export {};
//# sourceMappingURL=array.d.ts.map

@@ -1,4 +0,4 @@

/* eslint-disable no-param-reassign */ import { isArrayOfRows } from '../../utilities/isArrayOfRows.js';
import { isArrayOfRows } from '../../utilities/isArrayOfRows.js';
import { traverseFields } from './traverseFields.js';
export const transformArray = ({ adapter, arrayTableName, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts })=>{
export const transformArray = ({ adapter, arrayTableName, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale })=>{
const newRows = [];

@@ -32,2 +32,5 @@ const hasUUID = adapter.tables[arrayTableName]._uuid;

}
if (withinArrayOrBlockLocale) {
newRow.row._locale = withinArrayOrBlockLocale;
}
traverseFields({

@@ -51,3 +54,4 @@ adapter,

selects,
texts
texts,
withinArrayOrBlockLocale
});

@@ -54,0 +58,0 @@ newRows.push(newRow);

@@ -22,5 +22,10 @@ import type { BlockField } from 'payload';

texts: Record<string, unknown>[];
/**
* Set to a locale code if this set of fields is traversed within a
* localized array or block field
*/
withinArrayOrBlockLocale?: string;
};
export declare const transformBlocks: ({ adapter, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts, }: Args) => void;
export declare const transformBlocks: ({ adapter, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale, }: Args) => void;
export {};
//# sourceMappingURL=blocks.d.ts.map

@@ -1,4 +0,4 @@

/* eslint-disable no-param-reassign */ import toSnakeCase from 'to-snake-case';
import toSnakeCase from 'to-snake-case';
import { traverseFields } from './traverseFields.js';
export const transformBlocks = ({ adapter, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts })=>{
export const transformBlocks = ({ adapter, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale })=>{
data.forEach((blockRow, i)=>{

@@ -19,2 +19,3 @@ if (typeof blockRow.blockType !== 'string') return;

if (field.localized && locale) newRow.row._locale = locale;
if (withinArrayOrBlockLocale) newRow.row._locale = withinArrayOrBlockLocale;
const blockTableName = adapter.tableNameMap.get(`${baseTableName}_blocks_${blockType}`);

@@ -49,3 +50,4 @@ const hasUUID = adapter.tables[blockTableName]._uuid;

selects,
texts
texts,
withinArrayOrBlockLocale
});

@@ -52,0 +54,0 @@ blocks[blockType].push(newRow);

@@ -47,5 +47,10 @@ import type { Field } from 'payload';

texts: Record<string, unknown>[];
/**
* Set to a locale code if this set of fields is traversed within a
* localized array or block field
*/
withinArrayOrBlockLocale?: string;
};
export declare const traverseFields: ({ adapter, arrays, baseTableName, blocks, blocksToDelete, columnPrefix, data, existingLocales, fieldPrefix, fields, forcedLocale, locales, numbers, parentTableName, path, relationships, relationshipsToDelete, row, selects, texts, }: Args) => void;
export declare const traverseFields: ({ adapter, arrays, baseTableName, blocks, blocksToDelete, columnPrefix, data, existingLocales, fieldPrefix, fields, forcedLocale, locales, numbers, parentTableName, path, relationships, relationshipsToDelete, row, selects, texts, withinArrayOrBlockLocale, }: Args) => void;
export {};
//# sourceMappingURL=traverseFields.d.ts.map

@@ -10,3 +10,3 @@ import { fieldAffectsData } from 'payload/shared';

import { transformTexts } from './texts.js';
export const traverseFields = ({ adapter, arrays, baseTableName, blocks, blocksToDelete, columnPrefix, data, existingLocales, fieldPrefix, fields, forcedLocale, locales, numbers, parentTableName, path, relationships, relationshipsToDelete, row, selects, texts })=>{
export const traverseFields = ({ adapter, arrays, baseTableName, blocks, blocksToDelete, columnPrefix, data, existingLocales, fieldPrefix, fields, forcedLocale, locales, numbers, parentTableName, path, relationships, relationshipsToDelete, row, selects, texts, withinArrayOrBlockLocale })=>{
fields.forEach((field)=>{

@@ -42,3 +42,4 @@ let columnName = '';

selects,
texts
texts,
withinArrayOrBlockLocale: localeKey
});

@@ -63,3 +64,4 @@ arrays[arrayTableName] = arrays[arrayTableName].concat(newRows);

selects,
texts
texts,
withinArrayOrBlockLocale
});

@@ -91,3 +93,4 @@ arrays[arrayTableName] = arrays[arrayTableName].concat(newRows);

selects,
texts
texts,
withinArrayOrBlockLocale: localeKey
});

@@ -110,3 +113,4 @@ }

selects,
texts
texts,
withinArrayOrBlockLocale
});

@@ -140,3 +144,4 @@ }

selects,
texts
texts,
withinArrayOrBlockLocale: localeKey
});

@@ -164,3 +169,4 @@ });

selects,
texts
texts,
withinArrayOrBlockLocale
});

@@ -197,3 +203,4 @@ }

selects,
texts
texts,
withinArrayOrBlockLocale: localeKey
});

@@ -221,3 +228,4 @@ });

selects,
texts
texts,
withinArrayOrBlockLocale
});

@@ -246,3 +254,4 @@ }

selects,
texts
texts,
withinArrayOrBlockLocale
});

@@ -272,3 +281,4 @@ }

selects,
texts
texts,
withinArrayOrBlockLocale
});

@@ -309,2 +319,3 @@ }

baseRow: {
locale: withinArrayOrBlockLocale,
path: relationshipPath

@@ -355,2 +366,3 @@ },

baseRow: {
locale: withinArrayOrBlockLocale,
path: textPath

@@ -384,2 +396,3 @@ },

baseRow: {
locale: withinArrayOrBlockLocale,
path: numberPath

@@ -412,3 +425,4 @@ },

id: data._uuid || data.id,
data: data[field.name]
data: data[field.name],
locale: withinArrayOrBlockLocale
});

@@ -415,0 +429,0 @@ selects[selectTableName] = selects[selectTableName].concat(newRows);

@@ -304,2 +304,3 @@ import { eq } from 'drizzle-orm';

throw error.code === '23505' ? new ValidationError({
id,
errors: [

@@ -306,0 +307,0 @@ {

{
"name": "@payloadcms/drizzle",
"version": "3.0.0-canary.12a836c",
"version": "3.0.0-canary.1a675ae",
"description": "A library of shared functions used by different payload database adapters",

@@ -17,7 +17,14 @@ "homepage": "https://payloadcms.com",

"import": "./dist/index.js",
"types": "./dist/index.d.ts"
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./postgres": {
"import": "./dist/exports/postgres.js",
"types": "./dist/exports/postgres.d.ts",
"default": "./dist/exports/postgres.js"
},
"./types": {
"import": "./dist/types.js",
"types": "./dist/types.d.ts"
"types": "./dist/types.d.ts",
"default": "./dist/types.js"
}

@@ -43,6 +50,6 @@ },

"@payloadcms/eslint-config": "3.0.0-beta.59",
"payload": "3.0.0-canary.12a836c"
"payload": "3.0.0-canary.1a675ae"
},
"peerDependencies": {
"payload": "3.0.0-canary.12a836c"
"payload": "3.0.0-canary.1a675ae"
},

@@ -49,0 +56,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc