Skip to content

Commit

Permalink
Drop Unknown pine option errors in favor of TS and pinejs-client th…
Browse files Browse the repository at this point in the history
…rowing

Change-type: major
  • Loading branch information
myarmolinsky committed Jan 15, 2025
1 parent 6e28400 commit c06e72a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
32 changes: 0 additions & 32 deletions src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ export type ExtendedPineTypedResult<
> = TBaseResult &
IfDefined<ExtraPineOptions, Pine.TypedResult<T, ExtraPineOptions>>;

const knownPineOptionKeys = new Set([
'$top',
'$skip',
'$select',
'$expand',
'$filter',
'$orderby',
]);

const passthroughPineOptionKeys = ['$top', '$skip', '$orderby'] as const;

// Merging two sets of pine options sensibly is more complicated than it sounds.
Expand Down Expand Up @@ -141,14 +132,6 @@ export function mergePineOptions<R extends object>(
return defaults;
}

// TOOD: Consider dropping in the next major
const unknownPineOption = Object.keys(extras).find(
(key) => !knownPineOptionKeys.has(key),
);
if (unknownPineOption != null) {
throw new Error(`Unknown pine option: ${unknownPineOption}`);
}

const result = { ...defaults };

if (extras.$select != null) {
Expand Down Expand Up @@ -257,21 +240,6 @@ const convertExpandToObject = <T extends object>(
);
}

// Check the options in this object are the ones we know how to merge
for (const expandKey of Object.keys(expandOption) as Array<
keyof typeof expandOption
>) {
const expandRelationshipOptions = expandOption[expandKey];

// TOOD: Consider dropping in the next major
const unknownPineOption = Object.keys(expandRelationshipOptions ?? {}).find(
(key) => !knownPineOptionKeys.has(key),
);
if (unknownPineOption != null) {
throw new Error(`Unknown pine expand options: ${unknownPineOption}`);
}
}

if (cloneIfNeeded) {
return { ...expandOption };
}
Expand Down
7 changes: 0 additions & 7 deletions tests/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,6 @@ describe('Pine option merging', function () {
});
});

it('rejects any unknown extra options', () => {
// @ts-expect-error b/c it's not typed
expect(() => mergePineOptions({}, { unknownKey: 'value' })).to.throw(
'Unknown pine option: unknownKey',
);
});

it('ignores any unknown default options', () => {
// @ts-expect-error b/c it's not typed
expect(() => mergePineOptions({ unknownKey: 'value' }, {})).not.to.throw();
Expand Down

0 comments on commit c06e72a

Please sign in to comment.