Socket
Socket
Sign inDemoInstall

orma

Package Overview
Dependencies
Maintainers
2
Versions
233
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orma - npm Package Compare versions

Comparing version 1.0.240 to 1.0.241

31

build/integration_tests/integration.test.js

@@ -553,2 +553,33 @@ "use strict";

});
(0, mocha_1.test)('handles mutates with no actions', async () => {
await (0, integration_setup_test_1.test_mutate)({
users: [
{
$operation: 'update',
id: 1,
posts: [
{
$operation: 'update',
},
],
},
],
});
// test passes if it doesnt crash
});
(0, mocha_1.test)('handles mutates with empty updates', async () => {
const res = await (0, integration_setup_test_1.test_mutate)({
users: [
{
$operation: 'update',
posts: [
{
$operation: 'update',
},
],
},
],
});
// test passes if it doesnt crash
});
mocha_1.test.skip('allows $identifying_fields override');

@@ -555,0 +586,0 @@ mocha_1.test.skip('handles manual guid + raw value linking');

4

build/mutate/statement_generation/mutation_guid_query.js

@@ -40,2 +40,6 @@ "use strict";

}, new Set());
// can happen for updates that dont do anything and so dont have identifying fields
if (all_identifying_fields.size === 0) {
return undefined;
}
const $where = (0, record_searching_1.get_identifying_where)(orma_schema, guid_map, mutation_pieces, piece_indices);

@@ -42,0 +46,0 @@ // must apply escape macro since we need valid SQL AST

@@ -75,2 +75,6 @@ "use strict";

.$identifying_fields;
if (!(identifying_fields === null || identifying_fields === void 0 ? void 0 : identifying_fields.length)) {
// to handle updates with no props
return undefined;
}
const where = (0, record_searching_1.get_identifying_where)(orma_schema, guid_map, mutation_pieces, [mutation_piece_index]);

@@ -77,0 +81,0 @@ // must apply escape macro since we need valid SQL AST

17

build/types/query/query_result_types.d.ts
import { OrmaSchema } from '../schema/schema_types';
import { DeepMutable, GetAllEntities, GetFields, GetFieldType, Keyword } from '../schema/schema_helper_types';
export type OrmaQueryResult<Schema extends OrmaSchema, Query extends object, Entity extends GetAllEntities<Schema> = never> = OrmaRecord<Schema, Entity, Query>;
export type OrmaRecord<Schema extends OrmaSchema, Entity extends GetAllEntities<Schema>, Query extends object> = Omit<{
import { GetAliases, OrmaQueryAliases } from './query_types';
export type OrmaQueryResult<Schema extends OrmaSchema, Query extends object, Entity extends GetAllEntities<Schema> = never> = Omit<{
-readonly [Key in keyof Query]: Query[Key] extends {
$from: any;
} ? OrmaRecord<Schema, Query[Key]['$from'], Query[Key]>[] | undefined : Query[Key] extends {
$from: GetAllEntities<Schema>;
} ? OrmaQueryResult<Schema, Query[Key], Query[Key]['$from']>[] | undefined : Query[Key] extends {
$escape: any;
} ? DeepMutable<Query[Key]['$escape']> : Key extends GetAllEntities<Schema> ? Query[Key] extends object ? Exclude<keyof Query[Key], Keyword> extends never ? never : OrmaRecord<Schema, Key, Query[Key]>[] | undefined : never : GetSchemaTypeForField<Schema, Entity, Key, Query[Key]>;
} ? DeepMutable<Query[Key]['$escape']> : Key extends GetAllEntities<Schema> ? Query[Key] extends object ? Exclude<keyof Query[Key], Keyword> extends never ? never : OrmaQueryResult<Schema, Query[Key], Key>[] | undefined : never : GetSchemaTypeForField<Schema, Entity, Key, Query[Key]>;
}, Keyword>;
type GetSchemaTypeForField<Schema extends OrmaSchema, Entity extends GetAllEntities<Schema>, Key, Value> = Value extends true ? Key extends GetFields<Schema, Entity> ? GetFieldType<Schema, Entity, Key> : any : Value extends GetFields<Schema, Entity> ? GetFieldType<Schema, Entity, Value> : any;
export type OrmaRecord<Schema extends OrmaSchema, Aliases extends OrmaQueryAliases<Schema>, Entity extends GetAllEntities<Schema>, Subquery extends object> = {
-readonly [Key in keyof Subquery & (GetAllEntities<Schema> | GetFields<Schema, Entity> | GetAliases<Schema, Aliases, Entity>)]: Subquery[Key] extends {
$from: GetAllEntities<Schema>;
} ? OrmaRecord<Schema, Aliases, Subquery[Key]['$from'], Subquery[Key]>[] | undefined : Subquery[Key] extends {
$escape: any;
} ? DeepMutable<Subquery[Key]['$escape']> : Subquery[Key] extends true ? Key extends GetFields<Schema, Entity> ? GetFieldType<Schema, Entity, Key> : "Unrecognized field name for value 'true'" : Subquery[Key] extends GetFields<Schema, Entity> ? GetFieldType<Schema, Entity, Subquery[Key]> : Key extends GetAllEntities<Schema> ? Subquery[Key] extends object ? OrmaRecord<Schema, Aliases, Key, Subquery[Key]>[] | undefined : any : any;
};
export type OrmaField<Schema extends OrmaSchema, Entity extends GetAllEntities<Schema>, Field extends GetFields<Schema, Entity>> = GetFieldType<Schema, Entity, Field>;
export {};
{
"name": "orma",
"version": "1.0.240",
"version": "1.0.241",
"description": "A declarative relational syncronous orm",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -8,3 +8,6 @@ import { expect } from 'chai'

import { generate_orma_schema_cache } from '../schema/introspector'
import { GlobalTestQuery } from '../test_data/global_test_schema'
import {
GlobalTestMutation,
GlobalTestQuery,
} from '../test_data/global_test_schema'
import { OrmaSchema } from '../types/schema/schema_types'

@@ -602,2 +605,35 @@ import {

})
test('handles mutates with no actions', async () => {
await test_mutate({
users: [
{
$operation: 'update',
id: 1,
posts: [
{
$operation: 'update',
},
],
},
],
} as const satisfies GlobalTestMutation)
// test passes if it doesnt crash
})
test('handles mutates with empty updates', async () => {
const res = await test_mutate({
users: [
{
$operation: 'update',
posts: [
{
$operation: 'update',
},
],
},
],
} as const satisfies GlobalTestMutation)
// test passes if it doesnt crash
})
test.skip('allows $identifying_fields override')

@@ -604,0 +640,0 @@ test.skip('handles manual guid + raw value linking')

@@ -57,2 +57,7 @@ import { apply_escape_macro_to_query_part } from '../../query/macros/escaping_macros'

// can happen for updates that dont do anything and so dont have identifying fields
if (all_identifying_fields.size === 0) {
return undefined
}
const $where = get_identifying_where(

@@ -59,0 +64,0 @@ orma_schema,

@@ -134,2 +134,8 @@ import { OrmaError } from '../../helpers/error_handling'

.$identifying_fields as string[]
if (!identifying_fields?.length) {
// to handle updates with no props
return undefined
}
const where = get_identifying_where(

@@ -136,0 +142,0 @@ orma_schema,

@@ -215,2 +215,3 @@ import {

GlobalTestSchema,
GlobalTestAliases,
'users',

@@ -217,0 +218,0 @@ {

@@ -153,2 +153,3 @@ import { OrmaSchema } from '../schema/schema_types'

// }>
export type OrmaQueryResult<

@@ -158,8 +159,2 @@ Schema extends OrmaSchema,

Entity extends GetAllEntities<Schema> = never
> = OrmaRecord<Schema, Entity, Query>
export type OrmaRecord<
Schema extends OrmaSchema,
Entity extends GetAllEntities<Schema>,
Query extends object
> = Omit<

@@ -169,5 +164,7 @@ {

-readonly [Key in keyof Query]: Query[Key] extends {
$from
$from: GetAllEntities<Schema>
} // if the value has a $from prop, it is always a subquery
? OrmaRecord<Schema, Query[Key]['$from'], Query[Key]>[] | undefined
?
| OrmaQueryResult<Schema, Query[Key], Query[Key]['$from']>[]
| undefined
: Query[Key] extends { $escape } // handle escaped constants

@@ -179,3 +176,3 @@ ? DeepMutable<Query[Key]['$escape']>

? never
: OrmaRecord<Schema, Key, Query[Key]>[] | undefined
: OrmaQueryResult<Schema, Query[Key], Key>[] | undefined
: never

@@ -200,2 +197,39 @@ : GetSchemaTypeForField<Schema, Entity, Key, Query[Key]>

export type OrmaRecord<
Schema extends OrmaSchema,
Aliases extends OrmaQueryAliases<Schema>,
Entity extends GetAllEntities<Schema>,
Subquery extends object
> = {
-readonly [Key in keyof Subquery &
(
| GetAllEntities<Schema>
| GetFields<Schema, Entity>
| GetAliases<Schema, Aliases, Entity>
)]: Subquery[Key] extends {
$from: GetAllEntities<Schema>
}
?
| OrmaRecord<
Schema,
Aliases,
Subquery[Key]['$from'],
Subquery[Key]
>[]
| undefined // subquery with $from
: Subquery[Key] extends { $escape } // handle escaped constants
? DeepMutable<Subquery[Key]['$escape']>
: Subquery[Key] extends true
? Key extends GetFields<Schema, Entity>
? GetFieldType<Schema, Entity, Key> // field_name: true
: "Unrecognized field name for value 'true'"
: Subquery[Key] extends GetFields<Schema, Entity>
? GetFieldType<Schema, Entity, Subquery[Key]> // renamed_field: 'field_name'
: Key extends GetAllEntities<Schema>
? Subquery[Key] extends object
? OrmaRecord<Schema, Aliases, Key, Subquery[Key]>[] | undefined // subquery with no $from
: any
: any // unhandled case, like {$sum: 'quantity'}
}
export type OrmaField<

@@ -202,0 +236,0 @@ Schema extends OrmaSchema,

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